的.htaccess重写规则到路径不改变网址(.htaccess RewriteRule to path without changing URL)

   IT问题网   2018-11-15 00:00:00

问 题

所以,我这个问题:

  1. 位于 http://example.com/
  2. 基地网站
  3. 位于 http://example.com/web2/ 第二个网站
  4. 在人们作出各种请求的第二个网站一样 http://example.com/myweb/pg1 和 http://example.com/web2/pg2

近日,并且由于我需要有一个自定义的新路径,第二个网站,但也保持了第一位的其他一些问题。

的ideia是允许用户访问第二网站在两个以下地址:

  • http://example.com/web2/
  • http://example.com/alternative-url-web2/

文件夹 / web2 / 实际上存在于服务器上,但我怎么能模拟文件夹 /替代-url-web2的/ 和"重定向"的要求,以 / web2 / ?

请注意,我不希望在浏览器的url改变,这必须是一个"沉默的重定向"。而且我也确保所有其他请求如 http://example.com/other 不被第二个网站重新定向。

感谢你。


更新

据@anubhava我可以简单地通过增加解决这个问题,我的的.htaccess :

 选项+了followsymlinks -multiviews
rewriteengine叙述上
的rewritebase /
重写规则^替代网址web2的(/.* |)$ / web2的$ 1 [l,nc]
 

这可能是工作正常,但我发现了以下内容:

  • http://ex.com/alternative-url-web2 将被重定向到 http://ex.com/web2/ (改变浏览器的url);
  • http://ex.com/alternative-url-web2/ 将被重定向到 http://ex.com/ (将浏览器的网址);
  • http://ex.com/alternative-url-web2/somerequest 工作正常,并不会改变浏览器的url;
  • http://ex.com/alternative-url-web2/index.php 工作正常,并不会改变浏览器的url;

网站注:

在 / web2 / 有一个的.htaccess 的的也许的可导致有线重定向行为上面......因此,这里是该文件的内容:

  ifmodule mod_rewrite.c
rewriteengine叙述上
的rewritecond%{} request_filename -f [or]
的rewritecond%{} request_filename -l [or]
的rewritecond%{} request_filename -d
。重写规则^ * $-[nc,l]
重写规则^(数据/ | js / |款式/ |安装/ |图标\ .ico |跨域\的.xml |机器人\ .txt) -[nc,l]
重写规则^ * $的index.php [nc,l]
 / ifmodule
 

可以内部重写规则,以的index.php 是造成这一切?如果是的话,我该如何解决?

解决方案

到的httpd.conf 启用了mod_rewrite和.htaccess,然后把这个code在<$ c c>的.htaccess$document_root 目录下:

 选项+了followsymlinks -multiviews
#开启mod_rewrite的上
rewriteengine叙述上
的rewritebase /

重写规则^替代网址web2的(/.* |)$ / web2的$ 1 [l,nc]
 

替代code:

 重写规则^替代网址web2 /?$ / web2 / [l,nc]
重写规则^替代网址web2的/(.+)$ / web2 / $ 1 [l,nc]
 

标签:重写规则路径改变扭转网址



分享:

  • 微信
  • QQ好友
  • QQ空间
  • 新浪微博


热门推荐

我怎样才能mod_rewrite的,并保持查询字符串?(How can I mod_rewrite and keep query strings)

problem i want to mod_rewrite a url to another page, but ...

如何从PHP脚本改变外观的URL(How to change appearance of URL from within a PHP script)

problem i have some php and html in the same file, and i ...

删除尾随的问号htaccess的(Removing trailing question mark with htaccess)

problem can someone help me understand this code # remov ...

URL重写GET参数(URL Rewrite GET parameters)

problem i want my url to look like the following www.web ...

htaccess的从XAMPP转向灯开的Ubuntu 13.10后不工作(启用htaccess的Apache中的Linux服务器)(htaccess is not working after moving from XAMPP to LAMP on ubuntu 13.10 (Enable htaccess in apache linux server))

problem my codeigniter project is running successfullyon ...

查询字符串和放大器;国防部重写(Query Strings &amp; Mod ReWrite)

problem i'm not too inexperienced with rewrite (not a mas ...

在.xml文件PHP的错误?(PHP error in .xml file)

problem ok firstly, i added this line to my .htaccess fil ...

使用Apache的mod_rewrite解析搜索引擎友好的URL(using apache&#39;s mod_rewrite to parse SEO friendly URL&#39;s)

problem how do i convert something like me.com/profile/2 ...

搜索引擎友好的URL(Search-Engine Friendly URLs)

problem i am working on building my first search-engine f ...

斜杠之后将文字与.htaccess的变量(Turn text after slashes into variables with HTACCESS)

problem i need to pass 3 variables with a url but using s ...

从URL删除字符与htaccess的(Remove Characters from URL with htaccess)

problem hopefully someone can see what i'm do ...

重定向所有的HTML扩展到.PHP(redirect all .html extensions to .php)

problem i want to update all the pages on a website to us ...

需要转义#(哈希/磅)字符在.htaccess重写规则(need to escape # (hash/pound) character in .htaccess rewrite rule)

problem the question is fairly simple but i w ...

如何使用的.htaccess重写规则改变下划线以破折号(How do I use .htaccess RewriteRule to change underscores to dashes)

problem i'm working on a site, and its cms used to save n ...

请求实体太大PHP(Request Entity Too Large PHP)

problem in one of my cakephp site, i got this error. req ...

的.htaccess使用PHP $ _GET缩短网址(.htaccess shorten URL using php $_GET)

problem i need to be able to shorten my page from: mydom ...

Gzip已融为一体pression通过的.htaccess不工作(Gzip compression through .htaccess not working)

problem i have been creating a site and checking it's spe ...

重定向www.subdomain.example.com到subdomain.example.com(redirecting www.subdomain.example.com to subdomain.example.com)

problem i've had some users trying to access a site that ...

添加尾随斜线的.htaccess(Add Trailing Slash .htaccess)

problem i'm trying to get the following effec ...

禁用所有的CGI(PHP,PERL,...)使用的.htaccess目录(Disable all CGI (php, perl, …) for a directory using .htaccess)

problem i have a directory where users can upload files. ...