htaccess的重写URL删除动态和静态子目录

问题描述:

如何从URL中使用的htaccesshtaccess的重写URL删除动态和静态子目录

example.com/theme/dynamicfolder/

删除动态&静态的文件夹名称example.com/

主题是静态目录& dynamicfolder是从MySQL数据库

我目前htaccess的脚本

Options -MultiViews 
RewriteEngine On 
RewriteBase/

RewriteCond %{HTTP_HOST} ^www\. [OR] 
RewriteCond %{HTTPS} off 
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ 
RewriteRule^https://%1%{REQUEST_URI} [NE,L,R=301] 

# external redirect to redirect old URL to pretty URL  
RewriteCond %{THE_REQUEST} /a\.php\?slug=([^\s&]+) [NC] 
RewriteRule^/article/%1? [R=301,L,NE] 


RewriteCond %{THE_REQUEST} /sitemap\.php [NC] 
RewriteRule^/sitemap.xml [R=301,L,NE] 

RewriteCond %{THE_REQUEST} /contact\.php [NC] 
RewriteRule^/contact [R=301,L,NE] 


# internal rewrite to forward to actual URL 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule ^article/([\w-]+)/?$ a.php?slug=$1 [L,QSA] 


RewriteRule ^sitemap\.xml$ sitemap.php [L] 
RewriteRule ^contact$ contact.php [L] 

在当前.htaccess文件根目录的终值。

添加以下内容:

RewriteCond %{REQUEST_URI} !^staticFolder/ 
RewriteRule ^(.*)$ staticFolder/anotherFolder/$1 [L,QSA] 

所以网址:

https://yourdomain.tld/any0therValue

https://yourdomain.tld/staticFolder/anotherFolder/any0therValue

可以从访问

但是在这种情况下,另一个文件夹应该被预定义。

+0

感谢您的回复,但无法正常工作 - RewriteRule^theme /([^/]+)/(.*)$ $ 2 [L,QSA] – pra021

+0

是[rewrite module](https://httpd.apache。 org/docs/current/mod/mod_rewrite.html)在apache中启用?因为它已启用[测试](http://htaccess.mwl.be/) – Hossam

+0

。请检查以上现有的htaccess脚本 – pra021