1
我在使用.htaccess文件重写URL时遇到了问题。我不知道正则表达式。我有这么多的博客,并使用在线重写规则生成器来生成URL并粘贴到.htaccess文件中。但没有人工作。我在Apache服务器的httpd.conf文件中启用了mod_rewrite模块。如何使用.htaccess文件重写URL?
我想重写下面的url。
我已经在OS-Win7上用Apache服务器开发了项目。
http://localhost:81/quora/tamilnanban/innerpage.php?url=why-you-should-avoid-watching-porn-on-android-smartphones
到
http://localhost:81/quora/tamilnanban/why-you-should-avoid-watching-porn-on-android-smartphones
我目前的.htaccess文件包含以下代码:
RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^.*$ ./index.php
#RewriteRule ^url/([^/]*)\.html$ :81/quora/tamilnanban/innerpage.php?url=$1 [L]
RewriteRule ^/quora/tamilnanban/([^/]*)\.html$ /quora/tamilnanban/innerpage.php?url=$1 [L]
上面这条规则也不能正常工作。请帮助我使用.htaccess文件实现网址重写。另外,如果我在上述步骤中犯了什么错误,请纠正我。提前致谢。
我已经用在.htaccess文件代码。现在url按预期显示在浏览器中。但是页面被重定向到localhost页面而不是预期的对应页面。请帮助我,如果需要更改代码中的任何内容。谢谢。 – Janaki
@Janaki究竟应该将页面重定向到哪里? – starkeen
我将在innnerpage.php中获取查询字符串值(url参数值),并根据url值显示页面内容。 – Janaki