簡體   English   中英

使用.htaccess使seo友好的url

[英]make seo friendly url using .htaccess

我正在嘗試使用.htaac​​cess來創建SEO網址
這是我的.htaccess:

AddDefaultCharset utf-8
Options +FollowSymLinks
RewriteEngine On

RewriteRule ^ads/([0-9]+) advertisement.php?ad_id=$1 [NC,L]
RewriteRule ^rss/([0-9]+)-([^/]+) rss.php?cat=$1 [NC,L]

#replace template folder with a fake folder named theme
RewriteRule ^theme/(.*) template/$1 [NC,L]

#replace /core/ajax folder with a fake folder named ajax
RewriteRule ^a/(.*) core/ajax/$1 [NC,L]

RewriteRule ^news/([0-9]+)-([0-9]+)$ direct.php?cat=$1&post_id=$2 [NC,L]
RewriteRule ^(.*)/([0-9]+)-([^/]+)$ direct.php?cat=$1&post_id=$2 [NC,L]
RewriteRule ^(.*/)page/([0-9]+)$ category.php?cat=$1&p=$2 [NC,L]



RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ category.php?cat=$1 [NC,L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(([A-Za-z0-9\-]+/)*[A-Za-z0-9\-]+)?$ $1.php [NC,L]

我想直接調用不帶.php的php文件,如果該文件不存在,則將請求發送到category.php,就像您在上面看到的一樣,當我將它們放在同一個文件中時,它們都無法正常工作,並且可以分別工作。
例如:
last-news.php是一個現有文件,運動不存在
我想成為這樣
1. http://example.com/last-news打開http://example.com/last-news.php
2. http://example.com/sport打開http://example.com/category.php?cat=sport
現在第2作品,但我不能使第1作品也
這里有人可以幫助我嗎?

我自己解決了這個問題,代碼是正確的,但是放置是錯誤的
只需更換

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ category.php?cat=$1 [NC,L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(([A-Za-z0-9\-]+/)*[A-Za-z0-9\-]+)?$ $1.php [NC,L]

與:

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(([A-Za-z0-9\-]+/)*[A-Za-z0-9\-]+)?$ $1.php [NC,L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ category.php?cat=$1 [NC,L]

並且工作正常...

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM