mod-rewrite

Apache rewrite, home page

て烟熏妆下的殇ゞ 提交于 2020-01-16 14:47:12
问题 I am trying to rewrite the "home page" of the website to www.example.com . The home page right now can be accessed via www.example.com/dir/userdo?action=home My thoughts are www.example.com is really www.example.com/index.html since apache auto hide the /index.html , so I tried RewriteRule /index.html /dir/user.do?action=home [PT,L] which does not work. Can someone give me an idea the right approach to this problem? Thanks 回答1: RewriteRule ^/$ /dir/userdo?action=home [L] the default index

301 redirect URL with variable

邮差的信 提交于 2020-01-16 12:02:28
问题 I want to use htaccess to 301 redirect (not rewrite) urls like: brands.php?brand=Sony to brands/Sony How can i do that? Appreciate your help in advance. 回答1: So your users are entering brands.php?brand=Sony into their browser, and being redirected? If I have that correct, it's simple: RewriteEngine On RewriteCond %{QUERY_STRING} brand=([^&]+) [NC] RewriteRule brands\.php brands/%1 [L,R=301] 来源: https://stackoverflow.com/questions/7796421/301-redirect-url-with-variable

301 redirect URL with variable

早过忘川 提交于 2020-01-16 12:01:49
问题 I want to use htaccess to 301 redirect (not rewrite) urls like: brands.php?brand=Sony to brands/Sony How can i do that? Appreciate your help in advance. 回答1: So your users are entering brands.php?brand=Sony into their browser, and being redirected? If I have that correct, it's simple: RewriteEngine On RewriteCond %{QUERY_STRING} brand=([^&]+) [NC] RewriteRule brands\.php brands/%1 [L,R=301] 来源: https://stackoverflow.com/questions/7796421/301-redirect-url-with-variable

.htaccess 500 error. RewriteRule not working as it should

天大地大妈咪最大 提交于 2020-01-16 08:47:09
问题 I have a problem with one of my .htaccess rewriterule: Server details: Server runs LiteSpeed Webserver not Apache, according to my host provider it's 100% compatible with apache mod_rewrite. Problem: I get 500 Internal Server Error when i use this code: <IfModule mod_rewrite.c> Options +FollowSymLinks Options +Indexes RewriteEngine On RewriteBase / RewriteCond %{HTTP_HOST} !^www\.mysite\.com$ [NC] RewriteCond %{HTTP_HOST} ^(www.)?([a-z0-9-]+).mysite.com$ [NC] RewriteRule ^(.*)$ %2/$1 [L,QSA

.htaccess regex rewrite rule

老子叫甜甜 提交于 2020-01-16 08:37:38
问题 I have the following regex: RewriteRule ^blogs/([^/]*)/([^/]*) blogs/index.php?blogger=$1&blog=$2 This works fine for the following cases: http://myurl.com/blogs/blog-name/blog-article/ http://myurl.com/blogs/blog-name/blog-article http://myurl.com/blogs/blog-name/ however it does not handle: http://myurl.com/blogs/blog-name How can I make the "/" separator optional in this regex? 回答1: I'd use: ^blogs/([^/]*)(/([^/]*))? And you'd just have to check and make sure that $2 is still correct (with

Apache: mod_rewrite: Spcaes & Special Characters in URL not working

假装没事ソ 提交于 2020-01-16 07:10:40
问题 i am using APACHE:mod_rewrite to define a set of rules for rewritting URLS i want this link to be displayed as /myDIR/walls.php?f=All&of=0&s=Newest -> All.html so i am using the following rule text from (.htaccess) RewriteEngine on RewriteBase /myDIR/ RewriteRule ^All\.html$ papers.php?f=All&of=0&s=Newest now these variables that are being passed as f=All of=0 s=Newest these are being used in query, OBVIOUSLY, and one of these variables, i.e f sometimes has values with spaces and special

How can I capture a fully qualified local URL path with mod rewrite?

半城伤御伤魂 提交于 2020-01-16 04:21:31
问题 How can I capture a fully qualified local URL path with mod rewrite? For instance, my project is located in http://{localhost}/projects/mywebsite/index.php I tried with this RewriteBase /projects/mywebsite/ but it does not work for ErrorDocument . my .htaccess, RewriteEngine on RewriteBase /projects/mywebsite/ ErrorDocument 404 /error.php I need to do ErrorDocument 404 /projects/mywebsite/error.php but it isn't dynamic. I have to change it in two places everytime for each project. Any ideas?

htaccess rewrite QueryString disappears in Apache 2.2 but works in 2.4

柔情痞子 提交于 2020-01-16 00:29:26
问题 Following is the rule: RewriteRule ^api/([\w-]+)/?$ api.php?method=$1 [QSA] On local Apache 2.4 server, it allows me to rewrite like: /api/create-account/?name=abcd to /api.php?method=create-account&name=abcd On production server, which is Apache 2.2, the request goes to api.php . But I find not query string parameter in my script. If I dump $_REQUEST , $_GET or $_POST , I only get empty array. What am I missing? 回答1: You need to turn off Multiviews: Options -Multiviews Multiviews is a mod

.htaccess redirect only working for part of the URL

此生再无相见时 提交于 2020-01-15 17:48:11
问题 I'm trying to redirect a bunch of URLs from an old site to the shiny relaunched site. My .htaccess is working with the first level of directories (i.e. example.com/directory is redirecting to example.com/newdirectory), but I'm having issues redirecting beneath that. Here's an example of one that's not working: Redirect 301 /Expertise/QuantitativeResearch/ /services/quantitative-research/ This goes to example.com/services/QuantitativeResearch - so the Expertise directory is being redirected,

mod_rewrite for query string

孤人 提交于 2020-01-15 15:54:27
问题 I have got 3 cases of mod_rewrite: http://www.domain.com/location/albania/tirana/tirana-airport http://www.domain.com/location/albania/tirana http://www.domain.com/location/albania The actual url for all these cases would be: http://www.domain.com/page.php?country=albania&city=tirana&location=tirana-airport Can you describe a mod_rewrite rule which can work for all 3 cases? Right now if a city or location is missing, the page returns 404. It only works if all the 3 parameters are present.