本文介绍了URL重写不工作的.htaccess的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想重写使用htaccess的网址,我试图给出另一种问题,但是在这里似乎没有在所有要工作,我仍然得到原始地址答案。这是我有:

 的http://localhost/inbox.php PG = 2
 

我想

 的http://本地主机/收件箱/ 2
 

我已经是被在.htaccess摆脱PHP扩展如下规则和刚才添加的最后一行

 选项+了FollowSymLinks -MultiViews

RewriteEngine叙述上
的RewriteBase /

的RewriteCond%{} REQUEST_FILENAME!-d
的RewriteCond%{REQUEST_FILENAME} \ PHP -f
重写规则^(。*)$ $ 1.PHP [QSA,L]
重写规则/(.*)$ /inbox.php?pg=$1//added这
 

解决方案

您的问题是,之前的最后一个行被定义为最后一个,这样你的规则必须高于RewriteConditions。更好地使用本规则集:

 重写规则^ /?收件箱/(\ d +)$ /inbox.php?pg=$1 [QSD,L]
的RewriteCond%{} REQUEST_FILENAME!-d
的RewriteCond%{REQUEST_FILENAME} \ PHP -f
重写规则^(。*)$ $ 1.PHP [QSA,L]
 

我说,你错过了,并使其mandetory您需要preFIX,经过该数字将遵循(至少一个)。

I am trying to rewrite the url using htaccess and I have tried answers given on another questions here however nothing seems to be working at all I still get the original url.this is what I have:

http://localhost/inbox.php?pg=2

I want

http://localhost/inbox/2

I already had a rule that gets rid of the .php extension in .htaccess as below and just added the last line

Options +FollowSymLinks -MultiViews

RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php [QSA,L]
RewriteRule /(.*)$ /inbox.php?pg=$1//added this
解决方案

Your problem is that the line before the last one is defined as the last one so your rule must be above that RewriteConditions. Better use this rule set:

RewriteRule ^/?inbox/(\d+)$ /inbox.php?pg=$1 [QSD,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php [QSA,L]

I added your needed prefix which you missed and made it mandetory that after that numbers will follow (at least one).

这篇关于URL重写不工作的.htaccess的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-19 08:06