Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [mod-rewrite]

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 beyond simple substitutions.

1
vote
0answers
39 views

Apache alias directory only working for index page, sub pages give 404 unless directory name is omitted [SOLVED] [closed]

So I've got this weird problem, I am trying to host a php codeigniter project but I can only access my index page all the other pages give me a 404 error I want it on port 81 so in ports.conf I have ...
0
votes
1answer
18 views

mod rewrite with two parameters and loading folder

I have domain example.com, when someone go to this domain, I need to automatically redirect to example.com/en/ and need /en/ to be a parameter of variable lang. RewriteCond %{REQUEST_FILENAME} !-d ...
2
votes
2answers
2k views

htaccess and 301 redirects - multiple domains

I have the following which redirects mydomain1.co.uk and mydomain1.com to www.mydomain1.com perfectly. RewriteCond %{HTTP_HOST} !^(.*)\.mydomain1\.com$ [NC] RewriteRule ^(.*)$ http://www.mydomain1....
1
vote
1answer
35 views

Add Trailing Slash for certain page types

I would like to add a trailing slash for certain static page types like .html, .asp and .pdf. I tried the following code in .htaccess but it is adding a trailing slash to all types of links. # Force ...
4
votes
2answers
4k views

How to set preferred domain with https in Google Webmaster Tools

I have registered a website and bought an SSL certificate, installed it and did some mod_rewrite rules to have all my traffic go to https://example.com. So all is working nicely from that perspective. ...
2
votes
1answer
130 views

.htaccess redirect with all parameters

I have a simple rule in the .htaccess file, to redirect all requests to inwork.php: RewriteRule .* php/inwork.php?refpage=%{REQUEST_URI} [L] But all parameters are missing. For the request http://...
1
vote
1answer
57 views

.htaccess rewrite conditions for https:// pre tag subdomains

I need some extra code in my .htaccess file that configures this HTTP request for HTTPS too! <ifmodule mod_rewrite.c> RewriteEngine on RewriteCond %{HTTP_HOST} ^(.*)\.example\.com RewriteRule ^...
1
vote
4answers
12k 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 ...
3
votes
2answers
30 views

Mod Rewrite proxy to different backend hosts

I have a virtual host with multiple ServerAlias host1.example.com host02.example.com etc. I match the same pattern and based on ServerAlias I want to proxy them to different backend hosts. What I ...
1
vote
1answer
31 views

How is the mapping done from …/script.php?one,1 to …/script/one/2?

There is a PHP script which evaluates one or two parameters via QUERY_STRING. This script should process the parameters via QUERY_PATH. The PHP file type should be omitted. Request of the form https:/...
2
votes
1answer
28 views

Problem with [R=301]

Some of my RewriteRules don't work if i put the [R=301]. why this don't work? RewriteRule ^sitemap\.xml$ sitemap.php [R=301,L] It shows a Forbidden error when i try to access the URL https://example....
2
votes
1answer
32 views

Rewriterule redirects to URL and shows different URL?

I've a website hosted on an Apache server which hosts other domains. Therefore, I can't access the Apache configuration. On our website, I've several domains. For one of them (domain example.com), I'...
2
votes
2answers
321 views

Redirect loop in .htaccess when removing trailing slash

I have the following .htaccess file: AddDefaultCharset utf-8 RewriteEngine on Options +SymLinksIfOwnerMatch RewriteBase / # redirect all www-requests to no-www # - RewriteCond %{HTTP_HOST} ^www\....
3
votes
1answer
1k views

Redirect all pages within subdirectory to new page

After redoing my webshop, I need to redirect every URL within a certain directoy to a new page. All URLs beginning ith example.com/shop/... should be redirected to the page located at example.com/...
2
votes
1answer
29 views

Rewrite rule not taking effect

I need to place a rewrite rule in my .htaccess file so that requests for http://example.com/jbossas/jboss-configuration are redirected to: http://example.com/jboss-server/jboss-configuration So I ...
3
votes
1answer
42 views

Multiple rules to rewrite the url

Why both rules don't work together and how can i fix it? Only the first one works... I think that there's a conflict between the two rules, but i did not found a solution yet ?p= is the querystring i ...
6
votes
2answers
126 views

Is Checking For mod_write Really Necessary?

Recently I noticed that many people post .htaccess files here with: <IfModule mod_rewrite.c> Sometimes this even appears several times in the file! It obviously checks to see if mod_write is ...
1
vote
2answers
87 views

mod_rewrite issue, won't work when links contain “-”

I've been looking into mod_rewrite for my simple PHP CMS for a couple of days now and I found a rule that was supposed to work for me: RewriteRule ^(\w+)/?$ view_post.php?url=$1 This is supposed to ...
2
votes
1answer
154 views

htaccess 410 url spam hack requests excluding site generated request

Our site was hacked and links to random content where added to the site. We completely removed the hacked site and put a new one in its place. Everything new including images and content, no other ...
1
vote
4answers
2k views

How can I redirect %26 in URLs to %2526 using a .htaccess rule?

I would like .htaccess to redirect: example.com/something_%26_else to example.com/something_%2526_else I'm importing a bunch of pages that have ampersands in the title from MediaWiki. These are ...
1
vote
1answer
285 views

RewriteEngine .htaccess rules end up redirecting to example.net/https:/example.net

I'm starting to learn about the Apache .htaccess and I have some issues in my website... RewriteEngine On RewriteCond %{HTTPS} off RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} RewriteCond %{...
4
votes
2answers
4k views

Remove query string from 301 redirect URL

I'm having some trouble with redirects and I haven't been able to get this to work. I want to make the following http://www.example.com/seasonal/christmas?p=15 redirect to http://www.example.com/...
4
votes
1answer
2k views

RewriteRule working on local server but not on remote server

I have a .htaccess file with one simple RewriteRule: RewriteEngine on RewriteRule ^([A-Za-z0-9-]+)$ ?site=$1 I want to have a URL like http://www.example.com/imprint and forward it to http://www....
2
votes
1answer
549 views

Htaccess redirect pages from subfolder to root directory while preserving any query string

I have moved pages in various sub directories to the root directory and want to set up a 301 redirect for each page and keep any query string that might be present. For example: www.example.com/...
3
votes
1answer
38 views

Problem with .htaccess for files having similar kind of names

I have a file with name lang.php and another file in the same folder with same lang_inst.php. The .htaccess am using is: RewriteEngine On Options -Indexes RewriteCond %{REQUEST_FILENAME} !-d ...
4
votes
1answer
202 views

Moved images to another folder - need help with htaccess rewrite rule for png

I had to move my image folder. Before it was example.com/shoplogo/(name*).png now its example.com/shop-logo/(name*).png just stuck with the rewrite rule :-(.
4
votes
1answer
60 views

Need to create a rewrite rule that will check certain characters in a query string variable and redirect it to another page

Need to create a rewrite rule that will check certain characters in a query string variable and redirect it to another page. Example: http://www/prowebmasters.com/index.html?test=123$4/56 I should ...
2
votes
1answer
33 views

.htaccess to redirect domain1 to domain2

I currently have a .htaccess file with the current lines to force HTTPS: RewriteEngine On RewriteCond %{HTTPS} off RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] My main domain is ...
3
votes
2answers
357 views

How can I rewrite an old URL using variables to a static html page?

I am trying to redirect old URLS to the new URLS, the old site used variables in the URL but the new site uses SEO friendly URLs. When I try to redirect the old URL, it is not redirecting correctly ...
1
vote
0answers
51 views

Combining password protection and redirects in .htaccess file

I'm a designer who developed a simple site with HTML and CSS. I'm completely new to .htaccess so it's not surprising I'm struggling to get the file to work as I want. Problem 1: I want to password ...
3
votes
1answer
149 views

Redirect 301 for Apache Sub directory and query string combination

I am getting 404 errors in Google Search Console for URLs like the following: http://www.example.com/newsite12121212121212/eg/st_tour/perma/ http://www.example.com/newsite12121212121212/eg/...
0
votes
1answer
35 views

.htaccess rewrite rules working on Mac Apache 2.2 but not on CentOS Apache 2.4

I've run into an issue when moving from a test server to a production server. I have a set of .htaccess rules in a file in the public_html site root: #Root directory htaccess RewriteEngine On # ...
2
votes
1answer
13 views

How to define RewriteRule to skip parameter in uri

I heve the following rule: RewriteRule ^/shop$ https://www.example.com/category the rule is working as expected with one exception: if in url there are parameter following the shop path, for example:...
2
votes
2answers
1k views

Google sitemap access error, something to do with .htaccess redirect from http://www. to http://

I recently updated the .htaccess of my site to redirect from http://www. to http://. It all works fine but now I've made some changes to my site and uploaded a new sitemap.xml to Google Search ...
1
vote
1answer
328 views

.htaccess redirect dynamic URL (with numeric ID) to remove “track” from the end

It seems to be easy, but I can't figure out how to solve it, nothing worked for me. I have a dynamic URL like: http://www.example.com/user/46/track and I want to redirect from that URL to http://www....
1
vote
3answers
150 views

Use .htaccess to rewrite a wildcard subdomain to a specific php file

I want to use a particular page in my site as any subdomain. I need something like this http://*.example.com/. So, as the user types http://user1.example.com/ or http://user2.example.com/ then the ...
1
vote
0answers
21 views

Disallow URLs made with mod_rewrite in robots.txts [closed]

Here is my robots.txt file: User-agent: * Disallow: /head.php Disallow: /head/ Disallow: /head Disallow: /header.php Disallow: /header/ Disallow: /header Disallow: /footer.php Disallow: /footer/ ...
1
vote
2answers
127 views

WordPress multisite ERR_TOO_MANY_REDIRECTS where the domain name ends up in the path for nonexistent pages

I have a WordPress multisite setup with subdomains. I have pointed five subdomains to it. I have also installed SSL to main domain and the other subdomains. I have written the below Redirect code for ...
1
vote
1answer
348 views

RewriteCond %{HTTPS} !=on is not working even though RewriteCond %{SERVER_PORT} !^443$ works

I have a requirement to check for non HTTPS URLs in htaccess. My understanding is that RewriteCond %{HTTPS} !=on will match all URLs that are not HTTPS. But upon testing, I find RewriteCond %{HTTPS} !...
1
vote
0answers
24 views

Error in SEO Friendly URL [closed]

I have below url structure http://example.com/blog.php?blogURL=user-already-has-more-than-max_user_connections-active-connections and I want to below http://example.com/blog/user-already-has-more-...
0
votes
2answers
4k views

Issue with Apache redirection [duplicate]

I want to redirect mysite.example or http://mysite.example or www.mysite.example or any other format given my user to http://www.mysite.example, I am able to achieve this by rewriting following lines ...
1
vote
2answers
484 views

Apache 2.2 Not Identifying Safari with HTTP_USER_AGENT

I have a web server that has to meet PCI compliance requirements. Their latest round of policy changes have removed support for Safari, after having removed support for Windows XP based IE clients. ...
1
vote
1answer
54 views

Apache rewrite existing rewritten url [closed]

I know how to create rewrite rules in Apache but what I don't know is how to rewrite a previously rewritten url. This is an old URL /boats-for-sale/fairline-squadron-55/1280 and I need to redirect ...
6
votes
3answers
14k views

Properly force SSL with .htaccess, no double authentication

I am trying to force SSL with .htaccess on a shared host. This means there I only have access to .htaccess and not the main VirtualHost configuration. I know you can put a rule in the VirtualHost ...
3
votes
1answer
93 views

HTTPS redirect, exclude script parameters from URL

My goals: 1. http://example.com/page/index.php -> https://example.com/page/ 2. http://example.com/page/ -> https://example.com/page/ 3. http://www.example.com/page/ -> https://example.com/...
6
votes
1answer
663 views

Rewrite wildcard subdomains in .htaccess to corresponding folders on the main domain while preserving the subdomain

I'm trying to rewrite a subdomain to a folder/file like this: name.example.com -> example.com/profile/name foo.example.com -> example.com/profile/foo xyzzy.example.com -> example.com/profile/xyzzy ...
2
votes
1answer
40 views

Are these 3 redirect rules equal?

I would like to redirect the non-https and non-www versions my domain to the https and www version of it. I'm a bit confused by the options. Are these redirect rules equal for my purpose? # REDIRECT ...
8
votes
3answers
17k views

htaccess redirect non-www to www with SSL/HTTPS

I want a rewrite rule that redirects everything to https:// AND www. For example http://example.com should be going to https://www.example.com This is what I have: RewriteEngine On RewriteCond %{...
1
vote
1answer
88 views

What redirect rules should I use for upgrading from gallery2 to gallery3

I have upgraded my gallery2 to gallery3, and notice that some links no longer resolve correctly. Since the proper way is to redirect these with a 301, that is the way I'm going. The following series ...
4
votes
2answers
6k views

Redirect from URL with parameters to SEO friendly URL in .htaccess

I have category page with this structure example.com/Category.php?Category_Id=10&Category_Title=some-text i want to write htaccess rules to redirect from example.com/Category.php?Category_Id=...