2015-05-25 55 views
0

下面是我的htaccess文件。htaccess文件重定向工作,但不適用於其他文件

Options -MultiViews 
RewriteEngine On 
RewriteCond %{REQUEST_FILENAME} !-d [OR] 
RewriteCond %{REQUEST_FILENAME} !-f 

RewriteBase/

ErrorDocument 404 /404.php 
RewriteRule ^([^/]+)/(\d+)/$ $1/$2 [R=301,L] 

RewriteCond %{THE_REQUEST} \s/view_campaign\.php\?var1=([0-9]+)\s [NC] 
RewriteRule^view_campaign/%1? [R=301,L] 
RewriteRule ^view_campaign/([0-9]+)$ /view_campaign.php?var1=$1 [L] 
RewriteRule ^([^/]+)/(\d+)/([^/]+)$ view_campaign.php?var1=$2&var2=$3 [NC,L] 

RewriteCond %{THE_REQUEST} \s/profile_view\.php\?id1=([0-9]+)\s [NC] 
RewriteRule^profile_view/%1? [R=301,L] 
RewriteRule ^profile_view/([0-9]+)$ /profile_view.php?id1=$1 [L] 
RewriteRule ^([^/]+)/(\d+)/([^/]+)$ profile_view.php?id1=$2&name2=$3 [NC,L] 

,這裏是我的網址/

http://localhost/profile_view/1/test 
http://localhost/view_campaing/1/test-campaign-name 

一些PHP代碼我的鏈接,view_campaign正確重定向。我可以說我view_campaign的鏈接工作正常。如果它出現在下面。

http://localhost/view_campaign/1/test-campaign-name-some-junk 
http://localhost/view_campaign/1 
http://localhost/view_campaign/1/ 

我想爲profile_view一樣。我複製粘貼相同的代碼在htaccess/PHP文件,並改變相關的事情。 問題是,如果我嘗試打開http://localhost/profile_view/1/testhttp://localhost/profile_view/1http://localhost/profile_view/1/ 被重定向到

http://localhost/view_campaign/1/test-campaign-name-some-junk 

我沒有關於htaccess的太多的瞭解。

請指教。

回答

0

我做出anubhava回答一些變化。現在,它工作正常。 以下是工作代碼。

ErrorDocument 404 /404.php 
Options -MultiViews 
RewriteEngine On 
RewriteBase/

RewriteCond %{REQUEST_FILENAME} !-d [OR] 
RewriteCond %{REQUEST_FILENAME} !-f 

RewriteRule ^([^/]+)/(\d+)/$ $1/$2 [R=301,L] 

RewriteCond %{THE_REQUEST} \s/view_campaign\.php\?var1=([0-9]+)\s [NC] 
RewriteRule^view_campaign/%1? [R=301,L] 

RewriteCond %{THE_REQUEST} \s/profile_view\.php\?var1=([0-9]+)\s [NC] 
RewriteRule^profile_view/%1? [R=301,L] 

RewriteRule ^view_campaign/([0-9]+)$ /view_campaign.php?var1=$1 [L] 
RewriteRule ^(view_campaign)/(\d+)/([^/]+)$ view_campaign.php?var1=$2&var2=$3 [NC,L] 

RewriteRule ^profile_view/([0-9]+)$ /profile_view.php?var1=$1 [L] 
RewriteRule ^(profile_view)/(\d+)/([^/]+)$ profile_view.php?var1=$2&var2=$3 [NC,L] 
1

有這樣說:

ErrorDocument 404 /404.php 
Options -MultiViews 
RewriteEngine On 
RewriteBase/

RewriteRule ^([^/]+)/(\d+)/$ $1/$2 [R=301,L] 

RewriteCond %{THE_REQUEST} \s/view_campaign\.php\?var1=([0-9]+)\s [NC] 
RewriteRule^view_campaign/%1? [R=301,L] 

RewriteCond %{THE_REQUEST} \s/profile_view\.php\?id1=([0-9]+)\s [NC] 
RewriteRule^profile_view/%1? [R=301,L] 

RewriteCond %{REQUEST_FILENAME} -d [OR] 
RewriteCond %{REQUEST_FILENAME} -f 
RewriteRule^- [L] 

RewriteRule ^(view_campaign|profile_view)/(\d+)$ $1.php?var1=$2 [L,NC,QSA] 
RewriteRule ^(view_campaign|profile_view)/(\d+)/([^/]+)$ $1.php?var1=$2&var2=$3 [NC,L,QSA] 
+0

你能解釋一下我錯過了什麼嗎? – Ironic

+1

@ 404您在view_campaign中的最後一條規則匹配每個網址,因此它永遠不會返回到view_profile頁面 –

+0

我用你的代碼,但它不工作,因爲view_campaign和profile_view都返回錯誤404。 – Ironic

相關問題