开发者

.htaccess RewriteRule won't work!

I'm usin开发者_开发百科g php switch[_get] in my menu system to create url.com/?p=page and I'd like that to change into url.com/page.html. But I can't make it work, maybe some of you know the right settings for this.

I'm currently using this as .htaccess:

RewriteEngine On
RewriteBase /
Options +FollowSymLinks
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
RewriteRule ^start(.*)\.html$ ?p=start$

Thank you!

Update:

I tried with the $1 but still the url is: ?p=start when I want it to be /start.html


Looks like you're missing the $1 in your last rule:

RewriteRule ^start(.*)\.html$ ?p=start$1
                                     ^^^^

EDIT After new information, try:

RewriteCond %{QUERY_STRING} p=([a-z0-9]+) [NC]
RewriteRule . /%1.html [L]

This captures the p= parameter from the querystring and uses it to rewrite to page.html


Try

RewriteRule ^start(.*)\.html$ ?p=start$1 [L]

See the one (1) at the end.


htaccess works the other way around.

It makes things like /start.html proxy to ?p=start however, you still have make the links themselves target /start.html.

So change all the <a href="?p=start"> to <a href="/start.html">.


you need

RewriteCond %{QUERY_STRING} ^p=(.+)$ [NC]
RewriteRule ^$ /%1.html? [R=301,L]

R=301 is to change the url in the browser, but you still need to update all links on the site:

<a href="?p=start"> to <a href="/start.html">

Edit: Try the updated one (it has a ? after html)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜