.htaccess REQUEST_URI only one character redirect

442 Views Asked by At

I'm basics to htaccess. I have an issue with htacess SEO Friendly URL.

For Ex: If the URL is like www.example.com/A then htaccess should redirect to browse-category.php?alphabet=$1

My Code, but not working:

RewriteCond %{REQUEST_URI} [a-zA-Z]{1}$
RewriteRule ^([a-zA-Z0-9-/]+)$ browse-category.php?alphabet=$1

If URL is like this www.example.com/add-business then it should redirect to $1.php.

Please help me and thanks in advance

1

There are 1 best solutions below

2
On

You can use this code in your DOCUMENT_ROOT/.htaccess file:

RewriteEngine On
RewriteBase /

# if a matching .php file exists then internally forward /file to /file.php
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1\.php -f [NC]
RewriteRule ^(.+?)/?$ /$1.php [L]

# otherwise forward to browse-category.php?alphabet=$1
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)$ browse-category.php?alphabet=$1 [L,QSA]