Mod_rewrite .htaccess Redirect Part Of A Query String

Nov 9, 2010

I'm struggling with a redirect problem. I need to redirect the following URL with mod_rewrite thorough .htaccess [URL] to the following [URL] So, basically I just need to remove the


However, the order is important. Sometimes

appears after other variables in the querystring. in this scenario I need the

to remain part of


Is this possible? To summarise, if &lang=php appears at the beginning of the query string, remove the &. If &lang=php appears anywhere else in the query string, the & must remain. I would change the script myself but unfortunately I am not the developer, and he doesn't seem too helpful at the moment; this is a quick fix.


Redirect Part Of String With Mod_rewrite?

Feb 6, 2011

I need a rule in my .htacess file to replace with an underscore and 301 redirect any part of a querystring that contains the space (%20) or the double space (%2520) character. So, for example, if a querystring contains the following parameter


The parameter needs to be changed in the URL and redirected to:


I need this as a temporary measure; unfortunately I do not have access to the PHP script that produces these parameters but I am waiting for them to be changed.

View 2 Replies View Related

.htaccess - Mod_rewrite To Get Query String?

Jul 29, 2009

im now changing this site to another server and rewrite rule does not work. I cannot find the problem. I sent a support ticked to the hosting and they said:

If that statement doesnt work then it will be either incorrect, or not designed to work with the web server we are running. We use Apache version 2.2

The manual for mod_rewrite for apache 2.2 is here...


I have looked over and over this manual and I dont see what the difference is for my rule!

I want to get the text after the url/bank/ and send it to url/bank/index.php as a parameter called title! This rule does work on my other server space so I know that the rule does work!

The rule is:

RewriteEngine on
RewriteRule ^bank/([^/.]+)/?$ bank/index.php?title=$1 [L]

View 1 Replies View Related

Apache - .htaccess Redirect Subdirectory As Query String?

Jun 25, 2011

I want to create "SEO friendly" links that remove the query string from a web site. There is only one variable, let's call it "page". Here is the following code for my .htaccess file.

Options +FollowSymLinks
RewriteEngine On
RewriteRule ^(.*)$ index.php?page=$1

This works in providing the proper redirect. So /applications/ will send to index.php?page=applications.

My index.php will include a view page based on the value of $_GET['page']. Here is some sample code below:

switch ($_REQUEST['page']) {
include ("home.php");


Let's make apps.php an exact copy of home.php. home.php loads just fine, but apps.php will not load linked CSS and JScript pages. When apps.php is loaded, it thinks it is in the /apps/ directory. To load the linked pages, I would need to insert a "../" in front of the file name. Then it displays correctly.

How can I properly write the .htaccess file so the home.php and apps.php page can be identical files and produce identical results, instead of the apps.php file being treated as if it were in the /apps/ directory?

View 2 Replies View Related

Redirect Or Mod_rewrite An Expired Image In A Directory Using Htaccess?

Mar 31, 2011

I have a redirect setup that looks for an image in a directory and if it does not exist, it will redirect to a php file that resizes an image and saves it to that directory. I got it to work great. Problem now is that I need to find a good way to redirect it if the image that was written is 4 hours old. I looked into Mod_expires but could not find a way to redirect to my php image resizer when the image is 4 hours old.

I know I could do this in PHP but the whole point was to reduce the server load by using apache instead of PHP. The site I'm working on gets several thousand viewers daily so I really need to efficiently cache the resized images. Here's an example of what I'm doing...

Browser requests ""
Apache Checks if "" exists
If it does not exist, redirect to to "/image/resize_image.php" and generate a thumbnail in "/images/" folder

Now that I got that working how do I get it to redirect to "/image/resize_image.php" when the "1234_01_thumb.jpg" gets x hours old? At some point someone is going to have to update that photo especially if they uploaded the wrong one so it can't be permanent.

View 2 Replies View Related

Mod_rewrite And .htaccess - Redirect Script To Search Files In Inner Catalogs

Jul 9, 2010

I have a catalog /images and this path is used in a script. I need to redirect script to search files in inner catalogs - /images1 /images2 etc. I have such .htaccess but it doesnt work.

RewriteEngine On
RewriteOptions Inherit
RewriteBase /
RewriteCond %{REQUEST_URI} !^images/ [S=5]
# skip next 5 rules (number of lines following, i.e. 2*NDIR+1, where NDIR is number of imgdirs)

View 3 Replies View Related

.htaccess - Mod_rewrite If Query Contains Value?

May 16, 2011

Recently I solved my issue with mod_rewrite to redirect a domain to a subfolder. Now that I've fixed my original issue, I've hit a another wall.Here is an example structure:


For simplicity, /domain/ is the current and top-most folder. In /domain/index.php I am trying to access /content/styles.css. How can I accomplish this? Assume there is no web link to the previous directories. Also ../ does not work as ../ returns the same directory as ./. I thought of a way, but my .htaccess skills aren't very strong and I don't want to spend hours or days piecing together an answer. Let's say I have:

<link rel="stylesheet" type="text/css" href="content/styles.css" />

If I am right, href performs a request for the file. How can I use .htaccess to capture the request and point it to the correct folder? Like if the query string looks like ^/content/(.*)$, and rewrite it back one directory to access ../content instead.=

View 4 Replies View Related

Urgemt: .htaccess Redirect With Query Sting?

Apr 23, 2011

I want to redirect 5 pages with querystrings eg:


View 3 Replies View Related

Mod_rewrite Matching Both Subdomain And Query String

Jan 19, 2011

I'm currently mod_rewriting to page.php?this=123&that=abc with:

RewriteRule ^a/([^/]+)/([^/]+)/?$ page.php?this=$1&that=$2 [L]

Additionally I now want to mod_rewrite to page.php?this=123&that=abc So both and will redirect to page.php?this=123&that=abc My problem is matching both the subdomain and the query string. This is what I've been working on but it's still not rewriting properly.

RewriteCond %{HTTP_HOST} ^ [NC]
RewriteCond %{QUERY_STRING} /([^/]+)/([^/]+)/?$ [NC]
RewriteRule ^(.*) /a/$1/$2 [L]

Note that wildcard domains are set up (* It is just the htaccess mod_rewriting that is failing.

View 1 Replies View Related

.htaccess Redirect Non - WWW To WWW Preserving URI String

Nov 6, 2009

I'm running the CodeIgniter platform, which uses .htaccess to accept URLs like [URL] I currently use some .htaccess rewrites, namely (simplified):

RewriteEngine On
RewriteCond %{REQUEST_URI} !^(/index.php|/images|/assets)
RewriteRule ^(.*)$ /index.php/$1 [L]

I want to add a rewrite rule that redirects all non www requests to www. I also want the URI string following the domain name to stay the same in the redirect. For instance, if a user makes a request for [URL], I want the .htaccess file to rewrite the request in the browser as [URL] and then process the request.

View 2 Replies View Related

CURL To Return Query String Of Re-writte URL (mod_rewrite)

Jun 9, 2011

I'm trying to tidy up the code of large site I developed a while back. The URLs are re-written using mod_rewrite. I am trying to build an array of associative arrays, each one containing the page title, URL, query string (I used query strings in conjunction with a controller to load pages) and some other things. I really don't have time to build this list by hand.

So I'm trying to write a crawler that will start at index.php, get the page title, URL and query string, add them to an array, build a list of links to URLs on the same website and do the same for them, until all links are exhausted. I am trying to do this remotely from my localhost, although I could run it on my clients host account too.

So far I've gotten stuck because I don't know how to get the query string that is output when mod_rewrite rewrites the URL in the header. It also sucks because once I re-wrote those URLs, I went though the whole site and hard-coded the old internal links to the new SEO friendly URLs.

View 3 Replies View Related

APACHE Mod_rewrite Change Variable Name In Query String

Mar 27, 2011

I'm trying to change a variable name in a query string, so it's usable by my PHP code.

The query gets posts from an external system, so I can't control that they are posting a variable name with a space in it. And that makes it impossible for me to use the PHP $_GET function.

I need to change variable%20name to ?new1

And I need to change variable2 to new2

There are many variables passed in the query, but only these two need to be changed. The rest can stay the same or even disappear.

So ?variable%20name=abc&variable2=xyz

Needs to end up as ?new1=abc&new2=xyz

Also, they may not be in this order and there may be more variables

So ?variable%20name=abc&blah=123&blah2=456&variable2=xyz

Could end up as ?new1=abc&new2=xyz

OR as ?new1=abc&blah=123&blah2=456&new2=xyz

View 1 Replies View Related

Extract Part From URL For A Query String?

Jun 20, 2010

I need a certain part of a URL extracted.

Example: is the given URL.
blog/entry-title should be extracted.
However, the extraction should also work with[…]as the given URL.

This code is for a Content Management System.

What I've already come up with is this:

function getPathUrl() {
$folder = explode('/', $_SERVER['SCRIPT_NAME']);
$script_filename = pathinfo($_SERVER['SCRIPT_NAME']); // supposed to be 'index.php'
$request = explode('/', $_SERVER['REQUEST_URI']);
// first element is always ""
// now it's only the request url. filtered out containing folders and 'index.php'.
$final_request = array_diff($request, array_intersect($folder, $request));
// the indexes are mangled up in a strange way. turn 'em back
$final_request = array_values($final_request);
// remove empty elements in array (caused by superfluent slashes, for instance)
// make a string out of the array
$final_request = implode('/', $final_request);
if ($_SERVER['QUERY_STRING'] || substr($final_request, -1) == '?') {
$final_request = substr($final_request, 0, - strlen($_SERVER['QUERY_STRING']) - 1);
return $final_request;

However, this code does not take care of the arguments at the end of the URL (like ?standalone=1). It works for anchors (#read-more), though.

View 2 Replies View Related

Get The Value You Pass From One Page As Part Of The Query String?

Jun 20, 2002

How do you get the value you pass from one page as part of the query string i.e


How you you get the value of the variable in the next page, stumped.

View 4 Replies View Related

Multi-string Part Match In Query?

Feb 4, 2010

I am currently trying to query a db table which contains vehicle information and match as many parts of a passed string against a particular table field.VEHICLE TABLEVehicleID | Model | Trim LevelString to test for: 4dr 4WD LX ManualFor example, I need to match as many parts of the test string (4dr 4WD LX Manual) against the value in Trim Level then return the ID of the row that matches the best.So my question, is there a way to do this in one query OR do I need to loop it down using likes?

View 2 Replies View Related

Regex - Replacing A Specific Part Of A Query String ?

Jul 22, 2010

I use $_SERVER['QUERY_STRING'] to get the query sting.

A example would be a=123&b=456&c=789

How could I remove the b value from the query string to obtain a=123&c=789 where b can be any value of any length and is alpha numeric.

View 5 Replies View Related

Hide Query String In Url With .htaccess?

Feb 24, 2009

How to hide all query strings in my url and here i can't use hidden variables for these all because in all times i couldn't send them with form submission..And my page is having four query strings to be sent...

View 9 Replies View Related

Structure Query String In MVC Htaccess Applications?

Apr 1, 2011

I was wondering about creating "fake" URL queries in a web application. When you put a .htaccess file in the root folder of a project you can rewrite (behind the scenes) this URL into That way you can maintain a single access point and create a MVC application out of the path in $_GET["q"].But what about actual query strings? Surely this type of rewrite doesn't offer the flexibility of inputting a variable query string. Thus I liked the idea of the following: the minute you put & symbols in your URL, things get smelly. For that reason I'm currently replacing the & symbols with | symbols|limit=10|order=DESC

View 1 Replies View Related

Get Values From Query String And Pass It To New Page Using .htaccess File?

Jul 7, 2011

currently I m using following code in my site in .htaccess file :

RewriteRule ^([^/.]+).php?$ comman.php?cat=$1 [L]

This redirects user to comman.php page say, user requests

will redirects to

This works fine. My question is how can I achieve following

to redirect

i.e. whatever value passed to url using get method to add in my new url.

View 3 Replies View Related

Mod_rewrite In Htaccess

Sep 20, 2006

Been fooling around with mod_rewrite in htaccess but not getting anywhere. I would like if someone typed '' for it to be redirected to '' while still showing ''. How is that done?

I been reading it would have to be done by translating 'Me' to 'user.php?ID=123'. I don't mind updating the htaccess evertime someone chooses a new name. Meaning when someone chooses '' going into htaccess and making a new translation.

View 2 Replies View Related

Htaccess And Mod_rewrite

May 29, 2006

This is something new to me and i want to try and get it working. i have my own server with Apache 2, PHP 4 and MySql 4 with full access to everything. I put this in the.htaccess file:

RewriteEngine On
RewriteRule ^(.*)$ profile.php?user=$1

and nothing happened. I checked my Apache settings for the .htaccess file, and this is what it is set to:

AccessFileName .htaccess
# and never show them
<Files ~ "^.ht">
Order allow,deny
Deny from all

View 13 Replies View Related

.htaccess Mod_rewrite

Jul 10, 2005

I'm using .htaccess on a personal site of mine, on a local Apache 1.3 server. I have the following lines in my file: Quote:

RewriteEngine on
RewriteRule !.(gif|jpg|png|css)$ /includes/

I obviously have a page at includes/ with a simple: Quote:

print "hi?";

When I load a page in Firefox pointing to http://localhost/index.php (and any other page for that matter) it continuously loads, endless-loop style. I commented out the second line and the 'RewriteEngine on' causes no problems on its own, so it's just that second line that causes the browser to load and load and load.

View 6 Replies View Related

Mod_rewrite Via Htaccess

Nov 5, 2007

I have an app that requires mod_rewrite, which isn't enabled on the server. However, 1and1 support says I can enable it (I assume by htaccess), but they don't tell me how, but rather provide me with a few links from a Google search. how can i enable mod_rewrite via htaccess? What do I need to put in there? If mod_rewrite was enabled on the server, would there be a "default" config, or default statement or directives, whatever.

View 1 Replies View Related

Use Javascript To Redirect To A URL With A Query String?

May 31, 2010

<script type="text/javascript">
function Edit(id)

My problem is the Javascript is OK. The location href example. http://localhost/employee_set.php&edit=30 ...The PHP code is not working. Error is not found.

View 1 Replies View Related

Mod_rewrite .htaccess File?

Dec 19, 2008

For some weird reason this works on localhost but doesn't work on remote server---to remove .php extension from ALL php files

RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^([^.]+)$ $1.php [NC,L]

View 3 Replies View Related

Using A .htaccess File With Mod_rewrite?

Apr 22, 2009

I am using a .htaccess file with mod_rewrite. The code i am using is:

RewriteRule ^/?([-a-zA-Z0-9]+)/?$ outlets.php?outlet_ext=$1 [L]

This was working fine for me up until now. I just added a wordpress blog ( but when i try going to that url the mod_rewrite above seems to be kicking in.

View 6 Replies View Related

Little Mod_rewrite - Add To .htaccess File?

Jun 7, 2010

I have a classifieds website. Each classified is linked like this originally:

What RewriteRule should I use to make this link look like:

Also, what do I need to add to my .htaccess file? This is what I have so far:


And I have just enabled mod_rewrite which was disabled at first on my Ubuntu server by using: a2enmod rewrite. Anything else I need to know or do?

View 2 Replies View Related

.htaccess Mod_rewrite Options?

Nov 2, 2010

I have a problem with an htaccess url rewrite, that works fine at localhost but doesn't work on my hosting (anhosting).I need to redirect all the request to my index.php page.Here's an example: i would to redirect [URL]....This is my .htaccess:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]

on the hosting i always get redirected to the index.php file, but the $1 parameters results always blank, so my custom framework cannot handle the request correctly.

View 2 Replies View Related

Htaccess Mod_rewrite CPU Usage

Jun 2, 2007

If someone had lets say 1-3k files, all of which were accessed VIA mod_rewrite ... Do you think the CPU usage would be unbearably substantial?

View 1 Replies View Related

Parked Domains And Mod_rewrite In Htaccess

Sep 29, 2006

I have 3 parked domains on 1 home site. I have a 3 page php/mysql driven site. I want each of the 3 parked domains to be associated with a url variable. So: should go to should go to should go to should go to should go to should go to


I'm not looking to redirect because I want the address bar still to show not

View 1 Replies View Related

Mod_Rewrite Versus Htaccess File

Jan 4, 2004

Mod_Rewrite versus using .htaccess with Forcetype command. After reading several threads here and elsewhere about Mod_Rewrite it seemed like the answer to making the URLs search engine friendly.

Then articles using a '.htaccess' file with the ForceType command began to appear and quite frankly seems like a simpler and more secure way to go:

<Files FileName>
ForceType application/x-httpd-php

After a Google search for "ForceType application/x-httpd-php" numerous articles on the subject make it appear to be the preferred method for rewriting search engine friendly URLs.

View 1 Replies View Related

Link Duplicity With .htaccess And Mod_rewrite?

Sep 28, 2010

Here is my htaccess

RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ $1.php [L,QSA]

And this is my problem:

localhost/validpage gives me the contents of localhost/validpage.php.
localhost/validpage/blah also gives me the same (validpage.php) page and so does localhost/validpage/blah/blah/...
Therefore the problem I am facing is link duplicity(in my words!).

How do I allow localhost/validpage.php to be accessed from localhost/validpage only and nothing else, not even localhost/validpage.php.I have started a question on ServerFault too but with not much success.The answer I have got is it cannot be done with htaccess alone.By validpage I mean any valid page on the server. Since I am retrofitting an existing site with mod_rewrite for cleaner urls, I am looking for a relatively easy solution preferably with .htaccess only.

View 2 Replies View Related

Remove Http From URL In .htaccess (mod_rewrite)

Mar 2, 2011

I run a site where the content of the pages are generated based upon a URL. For example:


Would generate a mashup of content from [URL] and [URL]

The .htaccess i use for this (at is:

<ifModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{ENV:REDIRECT_STATUS} 200
RewriteRule .* - [L]
RewriteRule assets/.* - [L]
RewriteRule ^(.*)$ test.php?url=$1 [NC,L]

So basically the second URL is passed in a php string.

My question is this, I need to remove the http:// from the address using .htaccess

E.G. If someone types:


View 2 Replies View Related

.htaccess - Mod_rewrite: How To Catch .php Files

Sep 26, 2010

I'm trying to catch all .php requests so that my visitors won't be able to see the php magic I want [URL] to be redirected to [URL], but I don't want direct access to [URL]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

Although it seems to work at first glance, it doesn't prevent users from visiting [URL] directly. How would I solve this?


View 3 Replies View Related

Htaccess Mod_rewrite Conditions And Parameters?

Mar 21, 2011

rewrite rules of .htaccess, and some of the regular expressions there.i alredy have some rewrite rules definitions in htaccess, so if i call html file, it is executed as php.all i need now is if i open in browser like:[URL]to call file article.php?id=12345(id value can only be integer)

View 2 Replies View Related

Htaccess Mod_rewrite Not Working On Another Computer?

Nov 24, 2010

So I have an .htaccess file in a framework I am currently working on and it works on one computer but not on another. Both systems are windows 7 based and both are running WAMP Server 2.0.

RewriteEngine on
RewriteBase /home/
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+) index.php/$1 [L]

View 2 Replies View Related

.htaccess Mod_rewrite Has Different Result On Different Sites?

Feb 8, 2010

I am using mod_rewrite to create SEO URLs. Basically the thing works in the following way: all requests are caught by .htaccess and redirected to a php script (let's say transform.php). ransform.php parses SEO URL and transforms it into a normal URL, then includes index.php, then catches application's (index.php's) output and uses RegEx to convert all normal URLs to SEO URLs. So the vital step is to make all request go through transform.php. My .htaccess is rather long however I managed to limit it to the following lines.

<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^index.php?(.*)$ ./transform.php?p=$1&%{QUERY_STRING} [L]

The problem happens with the initial (root) URL: When I type and site is located on my local comp, everything works fine. is caught by .htaccess and sent to transform.php for further processing. However on another server this line doesn't work (let's say for This .htaccess line simply doesn't catch the request. Everything works fine for though.

Moreover I have several sites on this second server and some of them work while some of them don't. It's like for some of them the URL is first resolved to and then handled by .htaccess while for others the URL is not resolved and .htaccess deals with

View 1 Replies View Related

Force SSL / Https Using .htaccess And Mod_rewrite?

Dec 9, 2010

How can I force to SSL/https using .htaccess and mod_rewrite page specific in PHP.

View 2 Replies View Related

Query String - Capture S2d3f4 Value Using Http Redirect?

Feb 22, 2011

I have [URL] which redirects to [URL]. I want to capture s2d3f4. i have tried query string and it does not work . how to get that value? I am using http redirect.

View 2 Replies View Related

Htaccess - Use Script And/or Htaccess To Rewrite A URL But Not Redirect?

May 12, 2011

Is there a way I can use PHP (and/or .htaccess) to rewrite the URL of a page. For example if a user goes to[URL] they are actually accessing the page which is [URL] But not a redirect.

View 3 Replies View Related

Apache - Using Script To Assist .htaccess Mod_rewrite

Jul 20, 2010

I'm planning to use large amounts of URL rewrites on my website, but I can't get familiar with Apache's mod_rewrite because it's difficult and poorly documented.

I heard there's some option that allows invoking various scripts for the rewriting purpose.

View 2 Replies View Related

Exclude Subdomain From .htaccess Mod_rewrite Rules?

Dec 9, 2010

I'm not too familiar with .htaccess files, and I'm trying to exclude a subdomain (something like [URL]) from the following rewrite rule that's already in place:

RewriteEngine On
RewriteCond %{HTTP_HOST} !^[URL][NC]
RewriteRule ^(.*)$ [URL] [L,R=301]

This rule prohibits anyone from just entering [URL] and forces the desired presentation of [URL] I've tried a few options of excluding a subdomain from this rewrite rule, but to no avail. Each of the directories on the site have their own .htaccess file, but it seems this one is still taking precedence.

View 3 Replies View Related

.htaccess - Convert Clean Url To Normal Url By Mod_rewrite?

May 24, 2010

I have worked with clean URL in php. Now I want to convert a clean URL to normal php URL Like [URL]....

also i have one more question. Is there is any way to do this with out .htaccess?

View 2 Replies View Related

.htaccess Mod_rewrite Work Around For Loading Xml Files?

Mar 12, 2009

Here is my current htaccess code: (turn engine on and such) RewriteRule ^foo.xml$ bar.php [NC]. This code works fanstastic on domain names like [URL]... , etc. It does not work for temporary domains like such:

[URL]... Is there a work around for this?

View 2 Replies View Related

.htaccess Mod_rewrite For Site Looks Like To Have SEO Friendly Urls?

Feb 28, 2010

I'm trying to optimize my site to make it SEO and user-friendly, I have several problems to set the right mod_rewrite for the urls and need help for this, I'm new to it, so it's way beyong my knowledge for the moment. [URL], the site should look like this: [URL].

View 1 Replies View Related