URL Rewriting doesn't rewrite automatically

2019-02-20 03:42发布

I have this simple redirection on my website and it does not rewrite my url automatically, I have to type manual other URL to access it, what could be the problem, do I need to have something enabled in php.ini, below is the rewrite rule

RewriteEngine On
RewriteRule ^new-page-([^/]*)\.php$ /mypage.php?name=$1 [L]

标签: url php
3条回答
男人必须洒脱
2楼-- · 2019-02-20 04:01

I have the following link

www.preparationweb.com/Aptitude/Discussion/index.php?qid=26

I like it to appear it as

www.preparationweb.com/Aptitude/Discussion/26

Can you please provide me the code to be placed in .htaccess file according to the provided link. I have a godaddy hosting.

查看更多
够拽才男人
3楼-- · 2019-02-20 04:03

check your apache config (httpd.conf) see whether it allowing to overriding the htaccess

http://httpd.apache.org/docs/2.0/howto/htaccess.html

查看更多
Melony?
4楼-- · 2019-02-20 04:08

If you are doing it in .htaccess you should also specify RewriteBase /. Try

RewriteEngine On
RewriteBase /
RewriteRule ^new-page-([^/]*)\.php$ mypage.php?name=$1 [L]

This rewrites new-page-something.php tomypage.php?name=something internally.

ADDED:

Perhaps you want this:

RewriteEngine On
RewriteBase /
RewriteRule ^new-page-([^/]*)\.php$ mypage.php?name=$1 [L]
RewriteCond %{THE_REQUEST} ^(GET|POST|HEAD|TRACE)\ /mypage.php
RewriteCond %{QUERY_STRING} name=([^\&]*)
RewriteRule ^mypage.php$ new-page-%1.php? [R,L]

The first added RewriteCond checks whether the real request is requesting for /mypage.php to prevent a redirect loop. The second added RewriteCond is used to match the query string for use in RewriteRule.

查看更多
登录 后发表回答