简体   繁体   中英

URL Rewriting doesn't rewrite automatically

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]

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 to mypage.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.

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

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM