mod-rewrite

Using mod_rewrite to convert folders to querystring

What's the easiest way to convert these requests: http://www.example.com/en/ http://www.example.com/en/index.php To: http://www.example.com/index.php?language_id=en There's various PHP files, so the rule would also need to map http://www.example.com/en/anyfile.php To: http://www.example.com/anyfile.php?language_id=en The lang...

mod_rewrite number of parameters/back-references limitation

Apparently there is a limitation (9) on how many backreferences you can access in htaccess RewriteRules.. But we have a RewriteRule that requires more than 9 parameters, something like this: RewriteRule ^([^/]+)/b([0-9]+)(/a([0-9]+))?(/v([0-9]+))?(,([0-9]+))?(/(ajax|share))?(,complete)?$ /index.php?control=sites&site=brands&control_fil...

How to use RewriteRule like WordPress and Drupal

I have a website with an include script that will have a various number of variables. Here are some of the types of URLs and variables: Main page: index.php Login page: login.php (redirects to index.php after login). Logout page: logout.php (redirects to login after logout). Profile page: index.php?id=profile Users password page: index...

WordPress + mod_rewrite

Hi guys, I use Wordpress as a CMS, where the front page is static for the most part and the actual blog part of it has been moved to a new page that uses a custom page template that basically acts as if it were the front page on a standard Wordpress install. It works pretty well but it still has a few bugs. The main one is that paginati...

Force redirect to SSL for all pages apart from one

I'm trying to use apache2's mod_rewrite to force SSL connections to a website. So far, it's working fine with the following in the site's <VirtualHost> entry : RewriteEngine On RewriteCond %{SERVER_PORT} !^443$ RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [QSA,NC,R,L] This is working well, and redirects everything, which is what I wante...

How to make this work? RewriteCond %{ENV:UNIQUE_ID} !%{QUERY_STRING}

/foo/.htaccess does an internal redirect RewriteRule ^(.*)$ /bar/?%{ENV:UNIQUE_ID} /bar/.htaccess needs to recognise that the request was NOT internal, the issue is that I cannot figure out how to make the comparision work RewriteCond %{ENV:UNIQUE_ID} !%{QUERY_STRING} even a RewriteCond %{QUERY_STRING} %{QUERY_STRING} won't mat...

How do I create a recursive replacement in mod_rewrite?

I'm fairly new to mod_rewrite and I am attempting to convert a URL from http://example.com/foo/bar/blah/etc.html into http://example.com/stuff/foo_bar_blah_etc.html The assumption is that there is not a set number of directories between the domain and the file name therefore I cannot just write a single rewrite rule with 3 placehol...

How can I use URL rewriting to strip index.php from a URI?

Here's what I need- RegEx to match a url pattern and rewrite it to something else 301 redirect old pattern to new pattern Here's what I have- I have a url pattern that currently looks like this-- http://www.foo.com/press/index.php/2009/4-reasons-to-buy-now/ I want to create a pattern match on the url "http://www.foo.com/press/ind...

Mod_rewrite doesn't work for a url beginning in % (percent sign)

There are several links pointing to a site I manage in which the webmaster mistakenly included a space between the domain name and the page name: www.domain.com/ page.html When the user clicks, this gives www.domain.com/%20page.html I'd like to use mod_rewrite to redirect hits to the incorrect address to the correct addre...

How do you simply add new custom rewrites to the .htaccess of a wordpress without fail?

I've added some extra functionality to my wordpress so that I can visit it with a variable and do extra stuff. The problem is, when I turn my ugly dynamic link into lovely permlink formatting in the .htaccess file, wordpress overrides it / ignores it. I've heard there's a way to do it, but the ways I try to do it based off what people h...

writing mod_rewrite for form data

I am trying to rewrite an url with get-data from at form. This is working all good when committing strings with only English letters. But when commit Norwegian charachters (this is a Norwegian page), only the non-rewriten url is displayed. My mod_rewrite sentences looks like this: RewriteCond %{REQUEST_URI} /resultpage.php$ RewriteCond ...

URL Rewriting/Regex Debug

Hi guys, I need a set of fresh eyes on this. I'm having a tough time spotting the problem. In folder X I have an .htaccess file with the following two lines in it: RewriteEngine on RewriteRule ^([A-Za-z0-9\.-]+)/?$ item-display.php?bibid=$1 [NC,L] My interpretation is that anything in that directory will then be redirected to the ite...

Rewrite URL from http://example.com/blog/ to http://blog.example.com/

What RewriteRule (using .htaccess/mod_rewrite) should I use to redirect http://example.com/blog/ (with www or without) to http://blog.example.com/ ? I'm using the following, but getting a redirect loop: RewriteEngine On RewriteCond %{HTTP_HOST} !^www\.example\.com [NC] RewriteRule ^(.*)$ http://www.example.com/blog/ [L,R=301] Rewrite...

ISAPI Rewrite with instead of mod_rewrite

I'm installing Modx on windows with ISAPI Rewrite instead of apache with mod_rewrite? How do you define the rewrite rules? I'm guessing not with an .htccess file? any Ideas? Thanks ...

Apache and mod_rewrite: Redirect domain to subdirectory

(I know this is not a programming question per se, but it involves regular expressions, so at least it is borderline... ) The setup: Apache 2.0 with mod_rewrite on Windows. Two domains, let's call them domain1.example and domain2.example. I would like to host both domains on the same server ("server1"), so I point them to the same IP a...

How do i do readable urls?

Assume I have the url http://example.com/user/me, where me is the user name. When the user types the url into the address bar, I want to reveal the details of the user. I do not want urls such as http://example.com/user.php?user=me Any help appreciated, working on LAMP ...

Apache equivalent of lighttpd url.rewriteonce?

I have my application entry point like this. /app/index.php <-- this is the main dispatcher. And application specific folders under /app/ /app/todo/ /app/calendar/ /app/bugtrack/ Each application folder cotains application specific files. I would like to pass all requests unders app to pass through /app/index.php. So that. /app/...

The correct way to make a rewrite rule?

I have a .htaccess in my site www folder that has this rewrite rule: RewriteRule ^(\w+)/?$ /$1.php It works, if you type in http://sampardee.com/urltest - It finds urltest.php and brings it up. However, if you type in http://sampardee.com/urltest/ it still brings urltest.php up but the CSS stops working. I have the CSS file specified ...

foo.com/alice vs. foo.com/users/alice

It's of course nice to give users friendly URLs for their content on your site. But how best to do that? There are a lot of advantages to something like foo.com/users/alice, most importantly that you aren't cluttering up your root namespace. But I think simplicity for users trumps all that. A lot of big sites seem to agree (friendfee...

Making a rewriterule remove .php extension?

Hello, I have come up with a rewriterule to to go to any page on my website without typing in the .php extension because it is automatically added to the url. The rule is: RewriteRule ^(\w+)/?$ /$1.php It takes anything you type in my index and adds .php to it, so you can put in http://sampardee.com/index and it pulls up index.php Now...