简体   繁体   中英

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

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

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]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM