开发者

mod_rewrite prefix as a folder

I have this structure in my home directory:

  • /index.php
  • /.htaccess
  • /folderx/
  • /folderx/subfolder/
  • /folderx/subfolder/file.php

What I need, is to mod_rewite all requests with the prefix "folderx_" to the real folderx directory. But additionally, I need to force redirection - the user should't be available to request /folderx/subfolder/subsubfolder/file.php directly. It should be redirected to the mod_rewrite url: /folderx_subfolder/subsubfolder/file.php

  • /folderx_subfolder/ => /folderx/subfolder/
  • /folderx_subfolder/file.php => /folderx/subfolder/file.php
  • /folderx_subfolder/subsu开发者_如何学编程bfolder/ => /folderx/subfolder/subsubfolder/
  • /folderx_subfolder/subsubfolder/file.php => /folderx/subfolder/subsubfolder/file.php

I've tried the code below, but the redirect is not working properly. When requesting the subfolder, it redirects to the prefix, but I don't know how to prevent looping( Please, help! /folderx/subfolder/subsubfolder/file.php

RewriteCond %{REQUEST_URI} ^/folderx/(.*)$
RedirectMatch ^/folderx/(.*)$ /folderx_$1
RewriteRule ^folderx_([a-z]{3,15})(/?)+$ /folderx/$1/ [NC]
RewriteRule ^folderx_([a-z]{3,15})/(.*)$ /folderx/$1/$2 [NC]


RewriteRule ^folderx/(.+)$ http://example.com/folder_$1 [nc,last,redirect]
RewriteRule ^folderx_(.+)$ /folderx/$1 [nc]
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜