mod-rewrite

How do I convert a PHP query string into a slash-based URL?

旧时模样 提交于 2019-12-28 16:03:09
问题 I am a pretty skilled programmer, but when it comes to RegEx and rewriting, I am a total n00b. I want to convert a URL from http://www.example.com/lookup.php?id=1 to http://www.example.com/lookup/1/item/ where "item" refers to the name of an item in a database that is being looked-up. I'm using LAMP (Linux, Apache, MySQL, PHP) and I cannot, for the life of me, figure out how to convert the URLs so they are SEO friendly. 回答1: Simple .htaccess example: <IfModule mod_rewrite.c> RewriteEngine On

.htaccess rewrite pass all query strings through

喜你入骨 提交于 2019-12-28 14:55:24
问题 Currently I use: RewriteRule ^([^/\.]+)/?$ page.php?page=$1 [L] Which is good for when passing one querystring through. But is there a way just to pass all querystrings through? i.e. One page request might be: domain.com/contact?course=23 and another may be: domain.com/contact?workshop=41 So I need to know what the query string name is, but only ever one will be passed in at a time 回答1: If I understand your question correctly, you can just add the [QSA] (query string append) flag to the end

mod_rewrite with spaces in the urls

删除回忆录丶 提交于 2019-12-28 12:45:28
问题 I need to set up some RewriteRules to redirect a URL which has a space in it. I've tried this: RewriteRule ^article/with%20spaces.html$ /article/without_spaces.html [R=301,L] ... but it doesn't work. Putting in a space instead of %20 causes a 500 Internal Server Error. How do I add a space? 回答1: Try putting a \ in front of your space to escape it. RewriteRule ^article/with\ spaces.html$ /article/without_spaces.html [R=301,L] 回答2: You can just escape the space with a \ RewriteRule ^article

How to force the use of SSL for some URL of my Django Application?

我是研究僧i 提交于 2019-12-28 11:49:11
问题 I want to be sure that for some URL of my website, SSL will be use. I saw a lot of answer already on SO. Force redirect to SSL for all pages apart from one So I think I will use mod_rewrite . My question is more about how to configure the Virtual Host to run my Django Application over HTTP and over HTTPS without problems. I am using WSGI . Is it a problem to just duplicate the configuration over *:443 and over *:80 ? What should I do to have the best configuration? 回答1: If by WSGI you

%N backreference inside RewriteCond

一个人想着一个人 提交于 2019-12-28 10:10:34
问题 I'm working on a virtual domain system. I have a wildcard DNS set up as *.loc , and I'm trying to work on my .htaccess file. The following code works: RewriteEngine On RewriteCond %{HTTP_HOST} ^(www.)?example\.loc$ [NC] RewriteCond %{REQUEST_URI} !^/example/ RewriteRule (.*) /example/$1 [L,QSA] But, I want this to work with anything I put in. However, I need the %{REQUEST_URI} checked against the text found as the domain. I tried using this code: RewriteEngine On RewriteCond %{HTTP_HOST} ^

%N backreference inside RewriteCond

霸气de小男生 提交于 2019-12-28 10:10:12
问题 I'm working on a virtual domain system. I have a wildcard DNS set up as *.loc , and I'm trying to work on my .htaccess file. The following code works: RewriteEngine On RewriteCond %{HTTP_HOST} ^(www.)?example\.loc$ [NC] RewriteCond %{REQUEST_URI} !^/example/ RewriteRule (.*) /example/$1 [L,QSA] But, I want this to work with anything I put in. However, I need the %{REQUEST_URI} checked against the text found as the domain. I tried using this code: RewriteEngine On RewriteCond %{HTTP_HOST} ^

htaccess redirect index.php to root (including subdomains)

左心房为你撑大大i 提交于 2019-12-28 04:50:26
问题 I'm trying to redirect index.php files to the root /, I've searched around and found several snippets of code similar to: RewriteCond %{THE_REQUEST} ^.*/index.php RewriteRule ^(.*)index.php$ http://www.domain.com/$1 [R=301,L] This however won't work for subdomains, example below: I have a subdomain: subdomain.domain.com A user visits http://subdomain.domain.com/index.php Using the htaccess above they are redirected to http://www.domain.com/ rather than http://subdomain.domain.com/ Does anyone

Search and replace in apache htaccess a RewriteRule

余生颓废 提交于 2019-12-28 04:30:08
问题 I'd basically like to get /path/file+name+with+plusses.mp3 to rewrite to /path/file name with plusses.mp3 In my case wordpress is intercepting the request and giving a 404. But the file does indeed exist. Given the constraints of the regex in mod_rewrite implementation, I haven't yet seen a straightforward way of doing this. 回答1: Try this rule: RewriteRule ^([^+]*)\+(.*) $1\ $2 [N] 回答2: Well, I do have a solution, but I don't really like it... This will replace all underscores with dashes,

Reference capture groups of multiple RewriteCond in RewriteRule

若如初见. 提交于 2019-12-28 04:08:09
问题 When I have multiple RewriteCond chained together, only the capture groups of the last RewriteCond can be referenced with %0 - %9 . In the following problem the parameters in the query string of the url can be in any order. To parse them into a fancy url I would need to match each parameter in the query string individually: RewriteCond %{QUERY_STRING} param1=([^&]+) RewriteCond %{QUERY_STRING} param2=([^&]+) RewriteCond %{QUERY_STRING} param3=([^&]+) RewriteRule ^foo$ bar/%1/%2/%3/ [R] Like I

URL Rewrite GET parameters

拟墨画扇 提交于 2019-12-28 02:48:06
问题 I want my url to look like the following www.website.com/home&foo=bar&hello=world I only want the first get parameter to change However the actual "behind the scenes" url is this www.website.com/index.php?page=home&foo=bar&hello=world All tutorials I find change all of the parameters. Any help much appreciated! 回答1: Add this to your .htaccess in your web root / directory RewriteEngine on RewriteBase / RewriteRule ^home$ index.php?page=home&%{QUERY_STRING} [NC,L] If you want this to work for