mod-rewrite

Flipping a REQUEST_URI with ! in httpd.conf

Hi. I'm trying to set up a simple rule in my httpd.conf as a precursor to some more complex rules I need to set up. If I use this: RewriteCond %{REQUEST_URI} ^/test\.txt RewriteRule ^(.*)$ http://127.0.0.1:8080 [R,L] ... then a request for /test.txt goes to port 8080, as expected. But if I add a ! to flip the REQUEST_URI match, like...

Using custom environment variables in .htaccess

I need something like this: SetEnv foo bar.baz RewriteEngine On RewriteCond %{HTTP_HOST} ^%{foo}$ RewriteRule ^(.*)$ http://www.foo/$1 [L] UPD: I have made as follows: SetEnv HOSTNAME_ENV testsite RewriteEngine On RewriteCond %{HTTP_HOST} ^%{ENV:HOSTNAME_ENV} RewriteRule ^(.*)$ http://www.%{ENV:HOSTNAME_ENV}/$1 [L,R=301] But it d...

htaccess question

I have setup htaccess but i want increase the length of the rule so i need to know can i bypass one files, its currently 4 but i want to extend to 11- file i want to bypass is called shorten.php can i name a file that escapes the rule? RewriteCond %{REQUEST_URI} \/([0-9a-z]{4})$ [NC] RewriteRule ^(.*) http://www.x/forward.php?%1 [L]...

Rewrite for an empty query string

Hi all, I'm building in some caching to one of my sites, and I can't seem to find if there's a way to add a condition with mod_rewrite to apply only if the query string on a request is empty. For example, I'd love to know if I can have a request with no query string like http://www.example.com/ load the page at http://www.example...

problems working with 'rewrite' in apache2

I have the following list of URLs to rewrite: 1 write url /products/client/ send to /basedir/system/index.php?client=cliente 2 write url /product/client/index.php send to /basedir/system/index.php?client=cliente 3 write url /products/client/image/dir2/myimage.jpg send to /basedir/system/image/client/dir2/myimage.jpg 4 ...

apache mod-rewrite file name change

Hello all, This is probably straight forward for someone who know apache mod rewrite and regex but that someone is not me. This is what I am looking for : I just want to re-route image,css requests to one shared repository image/css file. e.g. we have 6-7 sites which can be on same server or different. Currently, image looks like thi...

More Eyeballs on my Poor mod_rewrite Attempt Please

We're changing the way users embed images in their blogs, but I need to make sure previously embedded images are still displayed. I'm trying to redirect legacy image embed links to either a static image or a single legacy image embed handling file. I'm using mod_rewrite, but it appears I fail. Amazingly, I've managed to cobble together ...

URL rewriting for different protocols in .htaccess

Hello. I need help with url-rewriting in .htaccess. So the issue is about different protocols: https and http. The main purpose of rewriting is to remove "www" from URL, but protocol should stay the same it was before. For example, when I have URL like http://www.domain.com/request, it should be redirected to the http://domain.com/req...

Rewrite rule to redirect html, but not any other files

I want my htaccess to redirect URL that end on ".html" to the index.php, but not any other files (so images can keep their href and still be displayed) This is how my htaccess looks like now, it works for the HTML redirect, but styles or images are not displayed (because they are also redirected, I guess) Options +FollowSymLinks Rewrit...

mod_rewrite - PHP: $_GET not complete

I have the following mod_rewrite: Options +FollowSymLinks RewriteEngine On RewriteRule ^register index.php?page=register The url looks like this: http://domain.com/register?param=foo&paramtwo=bar If I now print $_GET in PHP I get this: Array ( [page] => register ) but the other params aren't set. Must I change someting at the mod...

Problem with multiple rewrite rules

I have this rule which redirects all requests without a . in them to index.php, and it works fine: # Redirect all page requests to content handler RewriteRule ^([^.]*)$ index.php [L] Now I'd also like to disallow any requests where the original URL contains .php in it. When I add another rule like this (after the first one), the first...

Prevent executing .htaccess of parent folder

Hello I have two different sites on same domain for example: First site in the root directory http://example.com/ Second site in subfolder http://example.com/site2/ Each site have his own .htaccess When i enter to second site (http://example.com/site2/), in log of mod_rewrite i see that apache trying to execute .htaccess of first site (h...

mod_rewrite - friendly URLs and removing page extension

I need a little help with some mod_rewrite rules I am trying to use. I need to do 2 things Change a dynamic URL so that it’s friendly (e.g. /content.php?CategoryID=1 change to /categories/1/) Remove the .php extension on my pages (e.g. /page2.php to /page2) Ok so I can get number 1 to work by itself with the following in my .htacces...

mod_rewrite To Direct Subdomain Access

We are setting up an API and we want to use Apache mod_rewrite to direct all accesses to http://api.domain.com to the script located at /cgi-bin/api.pl. Here is what we're currently using: RewriteEngine on RewriteCond %{HTTP_HOST} ^api.domain.com$ [NC] RewriteRule ^(.*)$ /cgi-bin/api.pl [NC,L,QSA] However, this is giving us the follo...

How do I get the [L] flag of RewriteRule (.htaccess) really working?

To newcomers: While trying to comprehensively describe my problem and phrase my questions I produced huge ammount of text. If you don't want to read the whole thing, my observations about (read "proof of") [L] flag not working the misconception, from which it all sprung, is located in Additional observations section. Why I misunderstood ...

Hiding the get variables

I have a url that is constructed using get variables like location.href = this.href +'?type='+ escape($('#type_of_station').html()) + '&count='+ escape($('.number_changer').attr("id").slice(-1)); which gives me a url like the following http://posnation.com/pre_config/pre_config_step_2.php?type=Grocery&count=2 on the following...

Turning this string in modwrite

pre_config_step_2.php?type=Grocery&count=2 to /pre_config_step_2/Grocery/2 do i need to change the htaccess in the root directory and if so what do i change it to ...

Codeigniter / mod_rewrite: does not rewrite root folder because it is a folder.

Hey guys, using CodeIgniter I have the following problem on one specific webhost (locally and on my personal host it works just fine). I have a class function which redirects if the URL does not include a language parameter or a link. So if it is /, /home, /de/, etc. it redirects to /de/home. It works just fine if I request /folder/de...

Mod Rewrite Producing 404 When Crawled (works fine when viewed in browser)

I have the following code in my .htaccess: RewriteEngine On RewriteBase / RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] My pretty-link converting is done on my index.php. If the user is looking for something that doesn't exist, a 404 Header is produc...

How do I enable SEO-friendly URLs in CakePHP?

Hi, I want to do something like www.mydomain.com/page-slug point to www.mydomain.com/custom-pages/view/page-slug, something like Wordpress. How can I do this in CakePHP. ...