【发布时间】:2017-04-26 09:39:13
【问题描述】:
更新:在答案的帮助下,我能够获得此更新。我希望 .htaccess 中的以下表达式能够正常工作。 (.htaccess 的完整脚本也有问题共享)
RewriteCond %{REQUEST_URI} ((mypage2(/\d{4}-\d{2}-\d{2})?/\d{1,2}) |about-us)
RewriteRule ^(.+)$ /subsite/#/$1 [R=301,NC]
问题详情:
- 我已将 angularjs 子站点添加到现有的表达式引擎 php 站点。
- 子网站只有三个页面,在现有网站中非常慢
我希望 htacces 将这三个 url 重定向到新的子站点 url,例如 mydomain/page2/parameter1/parameter2 到 mydomain/subsite/#/page2/parameter1/parameter2 和 mydomain/page2/parameter1 到 mydomain/subsite/# /page2/parameter1
(这不是强制性的)在子站点中,我想使用history push state 清理/操作 URL 以显示用户 mydomain/page2/parameter1/parameter2 代替 mydomain/subsite/#/page2/parameter1/parameter2
我的 .htaccess 就像
RewriteEngine On
RewriteBase /
# Removes index.php from ExpressionEngine URLs
RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC]
RewriteCond %{REQUEST_URI} !/system/.* [NC]
RewriteRule (.*?)index\.php/*(.*) /$1$2 [R=301,NE,L]
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
# Directs all EE web requests through the site index file
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?/#/$1 [L,QSA]
关注是我最想要的东西
RewriteCond %{REQUEST_URI} ((mypage2(/\d{4}-\d{2}-\d{2})?/\d{1,2}) |about-us)
RewriteRule ^(.+)$ /subsite/#/$1 [R=301,NC] ==> when url is like mypage2(/date optional)/pagenumber then redirect it to subsite/#/mypage2(/date optional)/pagenumber
还有这个是可选的,如果没有达到我可以活
在我的 routing.js 中,我想像这样操作 url
$rootScope.$on('$stateChangeSuccess', function (event, toState, toParams,
fromState, fromParams, options, Data) {
var cleanUrl = window.location.toString().replace(subsite+'/#/', '');
window.history.pushState(null, null, cleanUrl);
//alert("Yes this works, it shows me the required url in browser at this moment");
//Here I am trying to clean the url
//But after that it reloads, some unwanted redirection happens after it
});
【问题讨论】:
-
如果你想避免附加 # 那么你可以选择 HTML5 模式而不是你的 hashbang 模式。
-
@JonStirling 错误的重复先生。我没有任何 php 文件来获取请求的 url。我在那里找不到任何几乎有用的答案。如果您坚持要复制,请指导我。查看已编辑的问题
-
@ImmanuelKirubaharanS 亲爱的,我想添加(如果不存在)而不是从 url 中删除 #
-
是的,我觉得这很愚蠢。我不应该提到 php,而是 apache。我只使用 php 服务而不是任何 php 页面或 php 文件来加载我的前端 url
标签: .htaccess url-rewriting url-redirection