I have an issue in my .htaccess file related to SEO friendly URL

Viewed 67

I am using RewriteRule for seo friendly URL its working fine but when I load project in browser its open search.php file instead of index.php file. My .htaccess file is below:

RewriteEngine on
RewriteCond %{THE_REQUEST} /([^.]+)\.php [NC]
RewriteRule ^ /%1 [NC,L,R]

RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^ %{REQUEST_URI}.php [NC,L]

#Adjust default time zone
SetEnv TZ America/Washington

ErrorDocument 404 http://localhost/estate2/404

RewriteCond %{REQUEST_URI} ^/404/$
RewriteRule ^(.*)$ <YourRelativePathToPHPFile>/404.php [L]

RewriteCond %{REQUEST_URI} ^/search.php/$
RewriteRule ^([^/\.]+)?$ search.php?type=$1
1 Answers

Based on your shown samples, could you please try following, written and tested with shown samples. Please clear your browser cache before testing your URLs. I have added 2 rules for search.php thing rest rules are from OP's shown .htaccess file.

RewriteEngine on
RewriteCond %{THE_REQUEST} /([^.]+)\.php [NC]
RewriteRule ^ /%1 [NC,L,R]

RewriteCond %{REQUEST_URI} ^/estate2/(house-for-sale)/?$ [NC]
RewriteRule ^ search.php?type=%1

RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^ %{REQUEST_URI}.php [NC,L]

#Adjust default time zone
SetEnv TZ America/Washington

ErrorDocument 404 http://localhost/estate2/404

RewriteCond %{REQUEST_URI} ^/404/$
RewriteRule ^(.*)$ <YourRelativePathToPHPFile>/404.php [L]
Related