htaccess的URL和目录重定向 [英] .htaccess URL and directory redirect
问题描述
这是我的第一篇所以原谅我,如果事情是错了我寻求帮助的途径。我一直在阅读有关我的问题的其他职位,但没有解决它。
我的路径:
... 等等。
我想改变的 / M / pageX属性为 / M /#pageX属性没有硬编码的URL并没有使用任何额外的PHP脚本。
一见钟情,我已经写了下面的.htaccess配置文件来完成这一任务:
选项+了FollowSymLinks -MultiViews
RewriteEngine叙述上
的RewriteBase /
重写规则^ [DM] /(。+)$ / M /#$ 1 [R = 302,NE,L,NC]
##隐藏PHP扩展
的RewriteCond%{THE_REQUEST} \ S / +通用_([^。] +)\。PHP [\ S?] [NC]
重写规则^%1 [R = 302,L,NE]
##在内部前进
的RewriteCond%{} REQUEST_FILENAME!-d
的RewriteCond%{DOCUMENT_ROOT} /common_$1.php -f
重写规则^(。+?)/?$ common_ $ 1.PHP [L]
- 是我的$ C C的最佳解决方案$或者有接近我的任务其他方式?
- 如何重定向/ M / pageX属性为/ D /#pageX属性?
感谢您
尝试在你的根目录的.htaccess这些规则(上述 / M /
A级和 / D /
):
RewriteEngine叙述上
重写规则^ D /(.+)$ / M /#$ 1 [NE,NC,L,R = 302]
重写规则^(。+)$ /#$ 1 [NE,L,R = 302]
确认为删除任何 /d/.htaccess
文件。
如果由于某种原因,你想从 /d/.htaccess
做到这一点,然后使用 /d/.htaccess $此规则C $ C>文件:
RewriteEngine叙述上
重写规则^(。+)$ / M /#$ 1 [NE,NC,L,R = 302]
This is my first post so excuse me if something it's wrong with my way of asking for help. I've been reading other posts related to my problem but none solved it.
My path:
... And so on.
I want to change the /m/pageX to /m/#pageX without hardcoding the URL and without using any additional php scripts.
At the first sight, I've accomplished this task by writing the following .htaccess configuration file:
Options +FollowSymlinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteRule ^[dm]/(.+)$ /m/#$1 [R=302,NE,L,NC]
## hide .php extension
RewriteCond %{THE_REQUEST} \s/+common_([^.]+)\.php[\s?] [NC]
RewriteRule ^ %1 [R=302,L,NE]
## To internally forward
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/common_$1.php -f
RewriteRule ^(.+?)/?$ common_$1.php [L]
- Is my code the best solution or there is other way to approach my task ?
- How can I redirect the /m/pageX to /d/#pageX ?
Thank you
Try these rules in your root .htaccess (a level above /m/
and /d/
):
RewriteEngine On
RewriteRule ^d/(.+)$ /m/#$1 [NE,NC,L,R=302]
RewriteRule ^(.+)$ /#$1 [NE,L,R=302]
Make sure to remove any /d/.htaccess
file.
If for some reason you want to do it from /d/.htaccess
then use this rule in /d/.htaccess
file:
RewriteEngine On
RewriteRule ^(.+)$ /m/#$1 [NE,NC,L,R=302]
这篇关于htaccess的URL和目录重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!