mod_rewrite is a URL rewriting module for the Apache web server. It is commonly used for so-called "pretty" URLs because of its ability to redirect on the server side (transparent to clients and their browsers), but also provides the power and flexibility to perform various request handling tasks ...

learn more… | top users | synonyms

-1
votes
0answers
15 views

Hiding and redirecting extensions on my webpage [duplicate]

I want to hide extensions on my webpage using the .htaccess file. I have managed to do it by using this code; RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^([^\.]+)$ $1.php ...
1
vote
2answers
30 views

What is the IIS equivalent of a rewrite rule that sends all requests to a PHP file?

I've always used Apache for all my web development work and I'm struggling to get my head around IIS. I've got an API that re-routes all requests to one particular file: 'api.php', how would I do the ...
0
votes
0answers
29 views

Apache mod rewrite rules for swapping directories [closed]

I am trying to correct for an issue where some dynamic urls were generated where the downstream directory paths were swapped with what is normal and then the links were published. For example: ...
5
votes
2answers
5k views

htaccess execution order and priority

Can anyone explain to me in what order apache executes .htaccess files residing in different levels of the same path and how the rewrite rules therein are prioritized? For example, why doesn't the ...
2
votes
1answer
147 views

URL rewrite from www.domain.com/sudirectory to http://domain.com/subdirectory

I need a solution for the following problem: I use a CMS and want the backend only be available at http://domain.com/backend and not at http://www.domain.com/backend. How do I have to change my ...
2
votes
1answer
37 views

How to add the ‘www’ prefix to my domain

I am trying to add www to my domain. I have the custom PHPcode on live server. I have workout GoDaddy forward options also but still my domain not forward. I have a site designed in Core PHPand was ...
1
vote
1answer
443 views

Using mod_speling with multi-level htaccess and rewriterules

We recently switched formats for managing our 301s. For the most part, everything went well, but it seems to have stopped mod_speling from working properly. Here's what we changed: old ...
1
vote
1answer
28 views

What rewrite rule would show the 410 (gone) status for removed forum URLs?

I have removed a forum system from my CMS and now I want to return an 410 status code whenever a search engine visits the former posts. I know that I have to use a number of Rewrite Rules to do the ...
1
vote
1answer
9 views

Bypass all rules and redirect internally to another folder/file

In Apache config file, there are some rules defines like below: <IfModule mod_rewrite.c> RewriteRule ^(Category)/([^/]+)/(.+)$ index.php?module=$1&id=$2&action=$3 [B,L,QSA] ...
1
vote
1answer
58 views

When a mod_rewrite redirect is in place, do absent <img>s still cost more server time than present <img>s?

I have a series of webpages in which the <html> refers to: <img src="img1.png" [...] /> <img src="img2.png" [...] /> <img src="img3.png" [...] /> After I realised that ...
1
vote
1answer
71 views

Redirecting domain to subfolder, one hosting account, avoid redirect loop. masking?

i know similar questions have been asked, but i've been at this for weeks. please humor me! i have two domains (giving actual domain names for simplicity and also to avoid in-head conversions for my ...
1
vote
2answers
383 views

RewriteRule /change-email.htm?e=someone@somewhere.com&h=xxxxxx

I need to rewrite URL's of this form: /change-email.htm?e=someone@somewhere.com&h=xxxxxx to: /change-email/?e=someone@somewhere.com&h=xxxxx I've done this in my .htaccess: RewriteCond ...
4
votes
2answers
257 views

Redirect non-www to www while preserving protocol

I am aware of the fact that there are tons of questions in this section and in server fault dealing with re-directions from non-www to www URLs. But I couldn't find one dealing with this issue while ...
2
votes
1answer
48 views

Using Mod_Rewrite To Block Referrer Based On Domain Extenstion?

I've been in web development for several years now (I'm a student web designer), and recently, I've begun to experiment with mod_rewrite for things like URL shortening. I was wondering, is it ...
0
votes
2answers
41 views

Remove folder name from rewritten URLs

Consider this URL: http://example.com/gallery/20141111-some-title In this URL I want to hide gallery/: http://example.com/20141111-some-title How can I achieve this using mod_rewrite? I used ...
1
vote
0answers
96 views

Can Apache .htaccess convert the percent-encoding in encoded URIs from Win-1252 to UTF-8?

I want to add a directive in my .htaccess, such that if the browser is pointed at a URI containing %E4 (ä) - or any other special character - the .htaccess automatically rewrites %E4 (ä) as %C3%A4 ...
1
vote
1answer
29 views

How can I pass optional URL parameters through my rewrite rule?

I created a CMS that identifies if the GET value of url is defined, and if it is, it returns the html contents of the page from the frontend template on index.php. This ideally is to make a templating ...
1
vote
2answers
2k views

Remove .php and id from URL and replace with slash

I have tried lots of URL rewrite rules in .htaccess but I am stuck now. I have to change this URL: products.php?id=31 to products/31 I have used: Options +FollowSymLinks -MultiViews ...
1
vote
2answers
129 views

Remove trailing slash and index.html in .htaccess

I seem to be stuck here trying to figure out how to redirect the following scenarios: /foo/index.html -> /foo (remove trailing slash, index.html as 301) /foo/ -> /foo (remove ...
2
votes
1answer
33 views

How use a canonical link tag in a dynamic page?

<link rel="canonical" href="http://www.example.com/category/subcategory/example-product/product-id" /> I have a whole bunch of query string URLs (company products) that I have rewritten to ...
2
votes
1answer
35 views

Forbid users from accessing a long URL while allowing access to a shorter one with mod_rewrite

I'm trying to block the following URL: www.example.com/Ayurveda/article/guna/alkalizing/contains/non-vegan/experience/relieves-burning But I want to allow: ...
2
votes
2answers
298 views

Error 404 after rewrite query strings with htaccess

I'm trying to redirect the URLs of a client's website like this: www.localsite.com/immobile.php?id_immobile=24 In something like this: www.localsite.com/immobile/24.php I'm using this rule in ...
2
votes
1answer
54 views

Geolocalization and Redirection

I have a multilanguage website. My project was to add the Geolocalization so base on the country that open the site to redirect in the specific url with the right language. The structure of the ...
4
votes
2answers
3k views

How to write a generic .htaccess file rule, regarding RewriteBase

The following rule in my .htaccess works just fine for routing calls to index.php: RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*)$ index.php [QSA,L] However, this does not ...
1
vote
1answer
42 views

htaccess RewriteRule: Premature ending of rewrite iteration?

I'm still trying to grasp the concept of Apache's RewriteRule, so please confirm if my understanding of the below is correct... So, here's a snippet of a website's .htaccess, I add numbers in front ...
1
vote
1answer
72 views

.htaccess rewrite rule domain alias doesn't work

I have a site called: www.example.com this is the main domain. Now I have a Alias: www.example2.com. I want that example2.com will be forwarded to a subdomain of the main domain to ...
1
vote
0answers
55 views

URL rewrite issue with cakephp

I am using cakephp framework 2.2.2 I want to create personalize URL for user if user enter username=pragnesh then they can access my site like http://pragnesh.mylocalhost.com same as in ...
0
votes
3answers
106 views

Always redirecting to https without www

First off all, I have searched and read multiple posts in this form and other websites on this matter and tested everything. Unfortunately the trial and error has not yet payed off. I am OK with ...
2
votes
2answers
365 views

Using .htaccess, can you hide the true URL?

So I have a web hotel with 1 main website http://www.myrootsite.com/ and a few websites in subdirectories, in a folder called projects. I have domain names pointing to the subdirectories, but ...
2
votes
1answer
45 views

Apache Redirect for Internal Traffic Only

We have a page, gateway.school.edu, where users have to fill out a recaptcha before being directed forward to our password reset. I would like any internal traffic, any user agent on our network with ...
2
votes
1answer
798 views

mod_rewrite doesn't work at all

I have my small website (made for study purposes) on localhost and I am trying to get .htaccess working (note that I am a complete beginner to .htaccess). So far, I have discovered that .htaccess is ...
0
votes
1answer
21 views

Trying to rewrite a URL to an existing URL with htaccess

I have a wordpress site up and it's been up for a while. Recently I was asked to change the URL of one of the pages. The current URL is: http://url.com/blog/category/newsroom They want the URL of ...
1
vote
2answers
101 views

Redirect Everything After slash (/) to another directory

I'm sure this is an easy thing to do but I can't seem to find the answer! I'm trying to redirect https://carddav.example.com/MYUSERNAME to ...
2
votes
1answer
147 views

Is it possible to check the case on Apache redirects or aliases?

I have a big website (15,000 pages) with a log list of redirects (about 800) that have been used in marketing pieces for years. My Apache server has been running mod_rewrite for the past 10 years or ...
5
votes
3answers
20k views

How to remove trailing slashes from URL with .htaccess?

The situation Across the entire domain, we'd like the URLs to hide file extensions and remove trailing slashes, independent of the domain name itself (as in, works on any domain). Sample of our ...
7
votes
1answer
2k views

.htaccess redirect url without trailing slashes

In my htaccess I have some rewrited urls like these: RewriteRule ^first-page$ /subdir/page.php?id_page=1 [QSA,L] RewriteRule ^second-page$ /subdir/page.php?id_page=2 [QSA,L] RewriteRule ^third-page$ ...
3
votes
2answers
85 views

Remove extension from URL using a rewrite without resulting in a redirect loop

On the server, I have a file (on the filesystem) called page.html, which I want to be accessed as site.com/page So if someone goes to site.com/page.html, it should 301 redirect to site.com/page I've ...
0
votes
4answers
43 views

Problem getting rewrite from subdomain to directory to work

I want to redirect demo.example.com to example.com/my-demo. This is my rewrite rule, but I'm not getting it to work on my production server: RewriteCond %{HTTP_HOST} ^demo\.example\.com ...
3
votes
2answers
72 views

non-cachable Canonical redirect of www to non-www

I know this question is debatable for the whole eternity, and most likely nobody knows the real philosophy of this problem. But I'm trying to solve the problem about 301 and 302 response headers in ...
1
vote
1answer
46 views

Rewrite URL with masking from HTTP to HTTPS site (on a different server) are certs needed on first server?

I have a *:80 virtual host in Apache 2.2.15 which is just a bunch of URL rewrites like: ServerAlias foo.bar biz.baz tit.tat RewriteRule / http://somesite.com (R=301,L) ServerAlias differentsite.com ...
3
votes
2answers
505 views

Apache Rewrite Rule non-www to www + http to https + remove trailing slash

I would like to accomplish the following: rewrite non-www to www redirect from http to https remove trailing slash e.g. http://example.co.uk should redirect to https://www.example.co.uk How ...
2
votes
1answer
69 views

Rehosting content from another server

We have a set of static pages that will augment a customer's existing site. The pages will not reside on the customer's servers for logistical reasons and because we need to maintain control of the ...
1
vote
1answer
429 views

Can't get Rewrite rule to keep original URL

I have these Rewrites, but I would like to have the URL stay the same as what is typed originally, I thought removing the [R] flags would stop it but it hasn't RewriteCond %{HTTP_HOST} ...
0
votes
2answers
26 views

Rewrite cond regex to split an url with a /

I'm struggling to correct the aftereffects a bogus redirect I made which led to a lot of 404s. I need to 301 redirect URLs that look like example.com/xysometext to example.com/xy/sometext ...
1
vote
1answer
6k views

How to setup mod_rewrite/htaccess to do url masking and forwarding to a subdirectory?

Its been about three years since I've played with apache and php(I've been using thin and nignx ;). So I've forgotten how to setup a mod_rewrite directive to forward all http requests from root to the ...
1
vote
1answer
75 views

Apache URL rewriting with masking and includes outside of DocumentRoot

I have an Apache 2.2.15 web server with the primary site at /web/mybiz which corresponds to http://mybiz.domain.com. We now have a new subdomain http://abc.mybiz.domain.com with the homepage living at ...
1
vote
1answer
538 views

Masking / mapping URL's with .htaccess

I've recently been trying to come up with a way of masking the visible URL in the browser (so not 301 redirecting) and still show the same content as the original URL. Here is the scenario... ...
0
votes
1answer
58 views

Google can no longer fetch pages after successful URL rewrites using an .htaccess file

I tried to rewrite my URLs so they no longer have the .html extension. But when I did this (successfully) Google can no longer crawl my pages when I use "Fetch as Google". Instead, it returns 404 ...
3
votes
1answer
312 views

How to redirect if directory does not exist or should not be seen?

I am using Apache and want to modify my .conf file for a website such that: If the request comes from my IP 1.2.3.4, just display the URL/page as requested If the request is not from my IP and the ...
1
vote
0answers
133 views

Apache, Rewrite Rule and Directories

I'm using the current virtual host: <VirtualHost *:80> ServerAdmin webmaster@mysite ServerName example.co.uk ServerAlias www.example.co.uk DocumentRoot ...