开发者

Remove subdirectory & remove .php extention in htaccess not working?

I m new to url rewrite:

First, here is what I am trying to accomplish: Current URL: www.example.com/subdirectory1/subdirectory2/something.php

Desired URL: www.example.com/subdirectory1/something/

And, the name of subdirectory2 is fixed.

Possible?

My current htaccess just to remove the ".php" but also not working. (Any idea how to debug htaccess??)

RewritEngine on 

RewriteCond %{REQUEST_URI} !\.php$ [NC]

RewriteCond %{REQUEST_URI} [^/]$

RewriteRule ^(.*)$ $1.php [L]

RewriteRule ^(?!su开发者_StackOverflow中文版bdirectory1/|subdirectory2/)(.+)$ subdirectory1/$1 [L]

Thanks.


Your first problem is RewritEngine on. You are missing an e. Should be RewriteEngine on.

Try this:

RewriteEngine on 

# Remove .php
RewriteCond %{REQUEST_URI} \.php$
RewriteRule ^([^/]+)/fixed/([^/]+).php$ /$1/$2/ [R=301,L]

# Rewrite "friendly" URL into php.
RewriteRule ^([^/]+)/([^/]+)/?$ /$1/fixed/$2.php [L]

This only works for exactly what you said. Fixed is always the same. Replace it with the correct value.

The users goes to: www.example.com/1234/fixed/5678.php. He is redirected to www.example.com/1234/5678

User goes to www.example.com/1234/5678. On the server, this becomes www.example.com/1234/fixed/5678.php.

Something like www.example.com/1234/5678/9abcd will not work. (More than two levels of directories.)

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜