简体   繁体   中英

Htaccess mod rewrite seo url setup

I have a site it was runing without seo, I changed links to seo urls. I create seo links and save them in db. and usaqe is : seo_url, all fine with php part but having problem with htaccess setup. I read tons of articles and questions about htaccess setup, and after all I came to this solution which is not working correctly.

need some help espacially in Upanel pagination part. Upanel is a folder.

closest answer was that one :

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f

RewriteRule ^home/?$ index.php [NC,L]

RewriteRule ^contact/?$ contact.php [NC,L]

RewriteRule ^Upanel/?$ Upanel/account.php [NC,L]

RewriteRule ^Upanel/page/?$ Upanel/account.php?page=$1[L]

RewriteRule ^reset-password/?$ forgot.php [NC,L]

RewriteRule ^change-password/?$ resetpass.php [NC,L]

RewriteRule ^user/?$ login.php [NC,L]

RewriteRule ^search/?$ search.php [NC,L]

RewriteRule ^hr-search/?$ ik.php [NC,L] 

RewriteRule ^sitemap/?$ rss.php [NC,L]

RewriteRule ^([a-zA-Z0-9_-]+)/?$ detail.php?p=$1 [NC,L]

RewriteRule ^category/([a-zA-Z0-9_-]+)/?$ categories.php?q=$1 [NC,L] 

Thanks for helps

For all your listed rules, Rewrite condition (RewriteCond) is not needed.

read the comments in the example below.

RewriteEngine On
# ^home index.php :request "starts with home"(^home) redirected to index.php,
# [NC,L] search is case insensitive(ie it also matches Home,hOme etc.
# [L] stop processing after this rule.
RewriteRule ^home index.php [NC, L]
# ^Upanel/page/ request starts with Upanel/page/ 
# (.*)$  "everything"(.*) after it "upto end"($) is stored in $1
RewriteRule ^Upanel/page/(.*)$ Upanel/account.php?page=$1 [L]

just modified your rules.

RewriteEngine On

RewriteRule ^home/ index.php [NC,L]
RewriteRule ^contact/ contact.php [NC,L]
RewriteRule ^Upanel/$ Upanel/account.php [NC,L]
RewriteRule ^Upanel/page/(.*)$ Upanel/account.php?page=$1 [L]
RewriteRule ^reset-password/ forgot.php [NC,L]
RewriteRule ^change-password/ resetpass.php [NC,L]
RewriteRule ^user/$ login.php [NC,L]
RewriteRule ^search/$ search.php [NC,L]
RewriteRule ^hr-search/$ ik.php [NC,L] 
RewriteRule ^sitemap/$ rss.php [NC,L]
RewriteRule ^([a-zA-Z0-9_-]+)/ detail.php?p=$1 [NC,L]
RewriteRule ^category/([a-zA-Z0-9_-]+) categories.php?q=$1 [NC,L]

See this.

RewriteRule ^Upanel/ Upanel/account.php [NC,L]
RewriteRule ^Upanel/page/(.*)$ Upanel/account.php?page=$1 [L]

here the second rewriteRule never work because every request which matches second condition also matched by first condition and L flag make sure it stops there at first condition. there for either of the following will work, choose with respect to your requirements.

RewriteRule ^Upanel/$ Upanel/account.php [NC,L]
RewriteRule ^Upanel/page/(.*)$ Upanel/account.php?page=$1 [L]

OR

RewriteRule ^Upanel/page/(.*)$ Upanel/account.php?page=$1 [L]
RewriteRule ^Upanel/ Upanel/account.php [NC,L]

see rewrite rule flags and answrers for order of rewrite rules

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