开发者

Question about url rewriting using apache mod_rewrite

开发者 https://www.devze.com 2022-12-12 19:42 出处:网络
I have a doubt about url rewriting using apache mod_rewrite. I am a newbie in mod_rewrite and I don\'t have any experience in regex.

I have a doubt about url rewriting using apache mod_rewrite. I am a newbie in mod_rewrite and I don't have any experience in regex.

What I want to do is to:

Rewrite / To /web/content/public/

Rewrite /clients/ To /web/content/clients/

How can I achieve above things.

I tried:

   <IfModule mod_rewrite.c>

   Options +FollowSymLinks
   RewriteEngine on

   RewriteCond %{REQUEST_FILENAME} !-开发者_高级运维f
   RewriteCond %{REQUEST_FILENAME} !-d
   RewriteCond %{REQUEST_FILENAME} !-l

   RewriteRule    ^/clients/$ web/content/clients/ [L]
   RewriteRule    ^(.*)$ web/content/public/$1 [L]
   </IfModule>

But it doesn't work. What can I do?


^(.*)$ includes the slash. So don't include the slash in the rewritten pattern. But include a root slash at the head of your rewritten pattern.

 RewriteRule    ^/clients(.*)$ /web/content/clients$1 [L]
 RewriteRule    ^(.*)$ /web/content/public$1 [L]

Check the apache access log and error log to see what kind of request URL comes back.

Please check the documentation, especially the list labeled "Here are all possible substitution combinations and their meanings:"


Try this:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -l
RewriteRule ^ - [L]
RewriteRule ^/clients/$ web/content/clients/ [L]
RewriteRule ^/(.*)$ web/content/public/$1 [L]

And if you want to use that rules in a .htaccess file, remove the leading slash from the patterns.

0

精彩评论

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