【发布时间】:2015-12-26 15:39:08
【问题描述】:
要做到这一点:
原始网址 -> localhost/viewprofile.php
重写网址 -> localhost/viewprofile/
我使用了这个代码。
# Apache Rewrite Rules
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
# Add trailing slash to url
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/|#(.*))$
RewriteRule ^(.*)$ $1/ [R=301,L]
# Remove .php-extension from url
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^([^\.]+)/$ $1.php
# End of Apache Rewrite Rules
</IfModule>
现在我用了
原始网址 -> localhost/viewprofile.php?user_id = 1
重写网址 -> localhost/1/
RewriteEngine On
RewriteRule ^([a-zA-Z0-9_-]+)$ viewprofile.php?user_id=$1
RewriteRule ^([a-zA-Z0-9_-]+)/$ viewprofile.php?user_id=$1
但不幸的是我想这样做
原始网址 -> localhost/viewprofile.php?user_id = 1
重写网址 -> localhost/viewprofile/1/
还有这个
原始网址 -> localhost/viewprofile.php?username=sean
重写网址 -> localhost/viewprofile/sean/
我有这两个Original URLs,我想将它们分别重写为上面给出的ReWrite URL。
任何人有任何解决方案?
【问题讨论】:
-
请简要说明您的问题,以便其他人理解并相应回答。
-
Original URL是我所拥有的,ReWrite URL是我想要实现的。 @PSN
标签: php .htaccess url mod-rewrite url-rewriting