htaccess重写url隐藏php问号

时间:2013-12-07 07:16:00

标签: php regex .htaccess mod-rewrite url-rewriting

我的网址格式mysite/profile/?theusername隐藏了php扩展程序,我试图在网址中隐藏问号所以网址会像mysite/profile/theusername一样,查找一些关于我应该做的帖子是添加外部重定向然后内部在htaccess转发,尝试了很多代码仍然无法使其工作。这就是我现在所拥有的:

Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /   

# Resolve .php file for extensionless php urls
RewriteRule ^([^/.]+)$ $1.php [L]

1 个答案:

答案 0 :(得分:1)

保持你的.htaccess像这样:

Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /profile/

# new rules
RewriteCond %{THE_REQUEST} \s/+profile/?(?:index\.php)?\?([^\s&]+) [NC]
RewriteRule ^ %1? [R=302,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/.]+)/?$ index.php?$1 [L,QSA]

# php hiding
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+?)/?$ $1.php [L]