有没有办法在不重新加载页面的情况下修改当前页面的URL?
如果可能的话,我想访问#hash 之前的部分.
我只需要在域之后更改部分,因此它不像我违反了跨域策略.
window.location.href = "www.mysite.com/page2.php"; // Sadly this reloads
Run Code Online (Sandbox Code Playgroud) 我想重定向www.example.com
到example.com
.以下htaccess代码实现了这一点:
RewriteCond %{HTTP_HOST} ^www\.example\.com [NC]
RewriteRule ^(.*)$ http://example.com/$1 [L,R=301]
Run Code Online (Sandbox Code Playgroud)
但是,有没有办法以通用方式执行此操作而不对域名进行硬编码?
应该何时在URL中使用尾部斜杠?例如 - 我的网址应该/about-us/
是/about-us
什么样的?
我完全了解SEO相关的问题 - 重复的内容和规范的事情; 我正在试图弄清楚在单独正确提供页面的上下文中应该使用哪一个.
例如,我的同事认为末尾的斜杠意味着它是一个"文件夹" - 一个"目录",所以这不是一个正确的风格.但我认为最终没有斜线 - 它也不太正确,因为它几乎看起来像一个文件夹,但它不是,它也不是普通文件,而是没有扩展名的文件名.
有没有正确的方法知道使用哪个?
我的.htaccess文件中有8行重写规则.我需要从这些规则中排除服务器上的两个物理目录,以便它们可以访问.现在所有请求都发送到index.php文件.
要排除的目录:"admin"和"user".
所以http请求:http://www.domain.com/admin/不应该传递给index.php文件.
ErrorDocument 404 /index.php?mod=error404
Options FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^www\.domain\.com$ [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,L]
RewriteRule ^([^/] )/([^/] )\.html$ index.php?lang=$1&mod=$2 [L]
RewriteRule ^([^/] )/$ index.php?lang=$1&mod=home [L]
Run Code Online (Sandbox Code Playgroud) 我有AngularJS种子项目,我已经添加了
$locationProvider.html5Mode(true).hashPrefix('!');
Run Code Online (Sandbox Code Playgroud)
到app.js文件.我想配置IIS 7以将所有请求路由到
http://localhost/app/index.html
Run Code Online (Sandbox Code Playgroud)
这对我有用.我该怎么做呢?
更新:
我刚刚发现,下载并安装了IIS URL Rewrite模块,希望这样可以轻松,明显地实现我的目标.
更新2:
我想这总结了我想要实现的目标(取自AngularJS Developer文档):
使用此模式需要在服务器端重写URL,基本上您必须重写所有链接到应用程序的入口点(例如index.html)
更新3:
我还在努力,我意识到我不需要重定向(有重写规则)某些URL,例如
http://localhost/app/lib/angular/angular.js
http://localhost/app/partials/partial1.html
Run Code Online (Sandbox Code Playgroud)
所以css,js,lib或partials目录中的任何内容都不会被重定向.其他所有内容都需要重定向到app/index.html
任何人都知道如何轻松实现这一点,而无需为每个文件添加规则?
更新4:
我在IIS URL重写模块中定义了2个入站规则.第一条规则是:
第二条规则是:
现在,当我导航到localhost/app/view1时,它会加载页面,但是支持文件(css,js,lib和partials目录中的文件)也被重写到app/index.html页面 - 所以一切都将到来无论使用什么URL,都返回index.html页面.我想这意味着我的第一条规则,即应该阻止这些网址被第二条规则处理,不起作用..任何想法?...任何人?...我感觉很孤单... :-(
我有一个看起来像这样的网址:
url.com/picture.php?id=51
Run Code Online (Sandbox Code Playgroud)
我如何将该URL转换为:
picture.php/Some-text-goes-here/51
Run Code Online (Sandbox Code Playgroud)
我认为WordPress做同样的事情.
如何在PHP中创建友好的URL?
我需要将每个http://test.com请求重定向到http://www.test.com.如何才能做到这一点.
在服务器块中我尝试添加
rewrite ^/(.*) http://www.test.com/$1 permanent;
Run Code Online (Sandbox Code Playgroud)
但它在浏览器中说
The page isn't redirecting properly
Firefox has detected that the server is redirecting the request for
this address in a way that will never complete.
Run Code Online (Sandbox Code Playgroud)
我的服务器块看起来像
server {
listen 80;
server_name test.com;
client_max_body_size 10M;
client_body_buffer_size 128k;
root /home/test/test/public;
passenger_enabled on;
rails_env production;
#rewrite ^/(.*) http://www.test.com/$1 permanent;
#rewrite ^(.*)$ $scheme://www.test.com$1;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
Run Code Online (Sandbox Code Playgroud) 如何"index.php"
在中心某处的codeigniter中删除每条路径中的延伸?我想要干净的非index.php-fied URLs
?
目前我正在使用lightspeed服务器托管.托管说mod_rewrite
已启用但我无法让我的脚本在那里工作.每当我尝试访问该URL时,它都会返回404 - 未找到的页面.
我将相同的代码放在另一台运行Apache的服务器上.它正在那里工作.所以我想,这是.htaccess
和mod_rewrite
问题.
但Hosting支持仍然坚持要求他们的mod_rewrite已启用,所以我想知道如何检查它是否实际启用.
我试着检查phpinfo()
,但没有运气,我找不到mod_rewrite
,是因为他们正在使用lightspeed
?
有没有办法检查?请帮帮我.谢谢.
仅供参考:我的.htaccess
代码是
Options -Indexes
<IfModule mod_rewrite.c>
DirectoryIndex index.php
RewriteEngine on
RewriteCond $1 !^(index\.php|assets|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ./index.php/$1 [L,QSA]
</IfModule>
Run Code Online (Sandbox Code Playgroud)
我也尝试过这样
DirectoryIndex index.php
RewriteEngine on
RewriteCond $1 !^(index\.php|assets|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ./index.php/$1 [L,QSA]
Run Code Online (Sandbox Code Playgroud)
但结果相同.
我们在Docker的常见域下有几个rails应用程序,我们使用nginx将请求定向到特定应用程序.
our_dev_server.com/foo # proxies to foo app
our_dev_server.com/bar # proxies to bar
Run Code Online (Sandbox Code Playgroud)
Config看起来像这样:
upstream foo {
server foo:3000;
}
upstream bar {
server bar:3000;
}
# and about 10 more...
server {
listen *:80 default_server;
server_name our_dev_server.com;
location /foo {
# this is specific to asset management in rails dev
rewrite ^/foo/assets(/.*)$ /assets/$1 break;
rewrite ^/foo(/.*)$ /foo/$1 break;
proxy_pass http://foo;
}
location /bar {
rewrite ^/bar/assets(/.*)$ /assets/$1 break;
rewrite ^/bar(/.*)$ /bar/$1 break;
proxy_pass http://bar;
}
# and about 10 more... …
Run Code Online (Sandbox Code Playgroud) url-rewriting ×10
mod-rewrite ×5
.htaccess ×3
php ×3
url ×3
nginx ×2
angularjs ×1
apache ×1
codeigniter ×1
friendly-url ×1
html ×1
iis ×1
javascript ×1
lightspeed ×1
proxypass ×1
redirect ×1
seo ×1
url-design ×1