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.

Filter by
Sorted by
Tagged with
3
votes
2answers
476 views

Send “410 Gone” response for URLs that are a “c” or “g” followed by digits

Is there anything i can use in my htaccess to send 410 code to all the links but not some links ? Example: I would like to 410 this urls (List is about 40k links) www.example.com/c1 www.example.com/...
2
votes
1answer
279 views

RewriteEngine On showing Apache test page

I have centos 7 and I need to put this .htaccess file inside one of my directories (www/html/forum) in order to display friendly URLs so instead of looking like example.com/index.php?user=222 it would ...
4
votes
2answers
2k views

The question mark ('?') in URLs is preventing htaccess code from blocking them

I want to block someone using this dynamic URL: REQUEST_URI = /%24%24%24%26%3f%26%3f%24%24%24?cmd=get_file&arg=images/wslogo_block_page.png&sid=3257F1B3D8C5432EB676D55891B428ED164A3561 There'...
3
votes
2answers
3k views

Redirecting directory without slash to directory with slash and https

I'm trying to redirect address: http://example.com/blog to address: https://example.com/blog/ Take into account that, I'm trying to redirect from NO HTTPS to HTTPS. So far, I achieved the desired ...
1
vote
3answers
4k views

Always redirecting to https without www

I have a website and have recently installed an SSL certificate. I want all links to the site to always redirect to the secure site without www, as I have made the SSL applicable to non-www. ...
5
votes
1answer
3k views

rewrite url - remove trailing / if any and add .php

I have a simple question, yet I've found no posts that answer my question. I need an htaccess file that rewrites the urls so that it removes the ending / if any, and adds .php no matter what the ...
5
votes
2answers
483 views

Properly redirect a site to WWW and HTTPS

I recently found out a problem in .htaccess file in my website. When I started the site I did a 301 redirect to redirect all non-www and http request to www with https. I added this lines of code and ...
2
votes
1answer
2k views

(nginx rewrite) add word on dynamic URL ending | word is repeated multiple in URL

I'm really confused by the Nginx rewrite rules. I have searched and found a lot of threads for rewrite rules but I don't get the required result... I have this form of a link: http://example.com/...
5
votes
1answer
69 views

.htaccess several domains to point to different locations

I have a main domain in a hosting plan and then several domains "parked" in the same hosting plan: main_domain.com domain1.com domain2.com domain3.com I need each of those domains to be MASK-...
2
votes
1answer
172 views

.htaccess and permanent redirection with a special condition

I have a WordPress website hosted on Bluehost which contains the following URL pattern: http://www.example.com/2017/01/30/sample-post/ I wanted to permanent redirect it to use this: http://www....
4
votes
1answer
383 views

.htaccess to WWW And/Or HTTPS

On my site I want to do these redirects: http[s]://example.com => https://www.example.com https://www.example.com => No Redirect http://sub.example.com => https://sub.example.com http[s]://www.sub....
1
vote
0answers
140 views

Create unique IDs between URL with nginx [closed]

I searched and tried nearly two weeks but don't get any useful result, so I'm trying my luck here before I get crazy: Every existing domain should get an unique ID right after the domain. The ID ...
2
votes
1answer
142 views

Clean URL using index files or mod_rewrite

Is it better to make clean URL's using index files in directories or simply using mod_rewrite rules to remove the file extensions?
1
vote
1answer
955 views

Mod Rewrite: HTACCESS How to rewrite a single URL to another?

I have read through a ton of other similar questions and have tried too many combinations of code, but nothing works. I just need to add a single rewrite (not redirect) to my htaccess: Here is the ...
2
votes
1answer
671 views

mod_rewrite part of the query string

I have a situation with opencart where I need to rewrite only the "route" leaving other query strings as it is. Example: http://www.example.com/?route=module/ext/products&category_id=15&sort=...
1
vote
2answers
218 views

Help with Apache mod_rewrite rules

I want to change some legacy URL's like this: /modules.php?name=News&file=article&sid=600 to this: /news/story/600/ This is what I have tried: RewriteEngine on RewriteCond %{QUERY_STRING} ...
2
votes
1answer
228 views

How to redirect multiple new domains back to their primary domain without negatively affecting SEO/Rankings or anything else?

I've searched Google high and low. There are many answers to this question. I even asked another question similar to this one however it lacked specificity. Something this question will not lack. I ...
2
votes
1answer
6k views

.htaccess syntax multiple RewriteEngine on

I'm learning to maintain my own WP site. After a lot of reading I ended up with my "complete" htaccess file that looks something like this DirectoryIndex index.php # Disable directory listings ...
3
votes
1answer
3k views

Rewrite subdomain to folder keeping the URL unchanged

I'm on a cheap shared hosting with Apache and I'm trying to do the following rewrite with .htaccess: http://anything.example.com/par1/par2 => http://example.com/anything/index.php?a=par1&b=par2 ...
2
votes
1answer
774 views

apache rewrite rule set for “whitelist or catchall” in .htaccess

On the dev version of a LAMP site (Apache 2.4 on Debian 8.5), my Apache rewrite rules implement a "whitelist then catch-all" concept. Specifically, images from images/, stylesheets from css/, ...
2
votes
1answer
341 views

Redirect query string URL via .htaccess

I am trying to redirect all query strings to a new URL. Search query example www.example.com/?s=cars to resolve to www.example.com/?search_gcse/?q=cars ("cars" is just an example). What is the ...
2
votes
1answer
608 views

Htaccess results in an Error on http to https change in proxy

I am having an issue trying to change my rewrite rule to use https. Before change, I had the following: RewriteEngine On RewriteBase / RewriteRule ^api/(.*)$ http://example.com/api/$1 [L,P] Which ...
1
vote
1answer
641 views

Rewrite URL with multiple queries

This article describes how to direct incoming traffic coming from "fake" URLs of this type: http://www.example.com/seo-sample/article-install-apache-on-linux.php to a PHP file that "really" uses ...
1
vote
2answers
715 views

To Fix HTTP 400-499 error codes with 301 redirects in .htaccess file

This issue is on WordPress site. I am aware we can change the URL naming convention in WP but I have changed my URL format from date format to simple postname followed by slug as shown below. Old ...
1
vote
1answer
255 views

How to eliminate space on .htaccess

Somehow a space was introduced in some of my URL like: /marques-voiture/Ford /marques-voiture/ Ford I attempted to correct that with the following rule on .htaccess RewriteCond %{REQUEST_URI} ^/...
6
votes
2answers
6k views

Have Apache show 404 at missing page URL instead of redirecting to error page URL

Assuming non-existent-page.html does not exist, and the user is trying to access that page and triggered a 404 error. Can i show the requested page URL: http://www.example.com/non-existent-page.html ...
0
votes
1answer
1k views

Firefox “The page isn’t redirecting properly” for a Wiki (all other Pages and UAs are OK) [closed]

We are having trouble with a website for a free and open source project. The website and its three components are as follows. Its running on a CenOS 7 VM hosted by someone else (PaaS). site: www....
2
votes
1answer
267 views

enable keepalive on apache 301 redirect pages

I want to make it so that every website on the server I manage (including my own website) will enable keep-alive on all (HTTP status 301) redirect pages including ones issued by apache modules. This ...
5
votes
1answer
6k views

.htaccess Direct all requests to Public dir when using framework etc

I using this .htaccess code to direct all requests to Public directory: <IfModule mod_rewrite.c> RewriteEngine On RewriteRule ^(.*)$ public/$1 [L] </IfModule> ...
3
votes
1answer
2k views

Apache htaccess - modify query string with mod_rewrite

I've recently changed scripting on my website, and this has resulted in a few 404 errors as some very old queries are no longer being redirected correctly. I've been trying to create a rewrite rule ...
1
vote
1answer
3k 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 blinksale....
3
votes
1answer
294 views

Using mod_rewrite to access httpOnly cookie?

I have Apache running as a secure proxy (Port 443) between an HTTPS site and the rest of the world. This site is setting a secure, httpOnly cookie. The cookie when seen in a trace shows up in a ...
1
vote
1answer
1k views

How do I get mod_rewrite working with TYPO3 and WordPress?

I've some trouble with TYPO3 (mydomain.net) and WordPress (mydomain.net/blog/) using mod_rewrite. First I was running a TYPO3 installation which uses mod_rewirte without trouble. Now I'm trying to ...
4
votes
1answer
12k views

mod_rewrite to edit cookies conditionally

Is it possible to use mod_rewrite to modify values in cookies based upon a condition? I am completely new to HTTP, but I have tried a thing or two. The only regex I know is Perl-style, I hope it is ...
0
votes
1answer
774 views

IP-based redirection using mod_rewrite

I'm running a small VPN server where each user has his own static IP. I set up an Apache server in order to host files for each of them and instead of using a new registration system, I wanted to take ...
4
votes
3answers
1k 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 ...
7
votes
2answers
7k views

When is the leading slash (/) needed in mod_rewrite patterns?

Here is an example from the Apache documentation for enforcing canonical hostnames: RewriteCond %{HTTP_HOST} !^www\.example\.com [NC] RewriteCond %{HTTP_HOST} !^$ RewriteRule ^/?(.*) http://www....
1
vote
3answers
14k 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 ...
2
votes
1answer
165 views

Routing URLs .htaccess file problem

When I click any link on my website it will show only the home page. http://example.com/article-rewriter When I add ?route=, the URL is correct: http://example.com/?route=article-rewriter/ How can ...
3
votes
1answer
76 views

Why does apache redirect to www without RewriteRule

So I have a webserver running on Apache, with a few virtual hosts. I want to default to https and hence I have a rewrite rule. <VirtualHost *:80> ServerName example.com ...
1
vote
1answer
114 views

mod_rewrite cause errors in apache error.log

In Opencart I have enabled SEO URLS, which is working fine, unless that I see errors in apache log: [Thu Apr 16 22:53:38 2015] [error] [client xy] File does not exist: /home/html/xy.eu/public_html/...
2
votes
1answer
1k views

How to remove trailing slashes from URL with .htaccess in localhost?

Here is my localhost folder structure: •www (wamphost folder) •example.com (folder) •index.php With the current the URL results: localhost/example.com/ The URL I would like is: ...
1
vote
1answer
41 views

Redirecting all traffic to a script

I am on Centos 6.5 with Apache2 and Perl 5.23. I need to pass all traffic to the single perl script, check this request in a database, and show needed content (have both static and dynamic content). ...
3
votes
1answer
400 views

Apache mod_rewrite problem with adding a query string on an internal rewrite

I need to replace /xyz with /index.html?dh=xyz. I use the following config in httpd.conf: RewriteCond %{QUERY_STRING} "!dh" RewriteRule "^/(.*)$" "/index.html?dh=$1" [R] This works perfectly if [R] ...
3
votes
2answers
506 views

Redirecting specific URL from HTTPS to HTTP

Long time lurker, first time caller... I have a backend like admin.mysite.com which is able to use HTTPS (has a certificate installed, etc) - but that admin portal is a CMS backend for a number of ...
2
votes
1answer
312 views

Crafting a regex for mod_rewrite with more than nine parameters

Say for example, I have a URL in this format: http://example.com/(mobile-or-desktop-flag)/(major-venue-category)/(smaller-venue-category)/(venue-name)/(month)-(day)-(year)/(picture-number)/(user-...
3
votes
1answer
246 views

Can Apache serve resources recursively if there's a 404 in the current directory?

Is there a possibility to serve resources hosted with Apache recursively across the directory hierarchy, using mod_rewrite or the like? Example#1: A server document css/php/html/... refers to the ...
2
votes
1answer
793 views

Redirect before rewrite

Had an issue where I need to redirect old URLs, but not disable the mod_rewrite for page structure. redirect 301 /home.html http://www.example.com/ It needs to live on the Symphony 2.0 .htaccess ...
2
votes
1answer
198 views

How to regex a url to redirect user

Using the regex and the .htaccess file, I want to redirect users to a certain URL. I want to redirect: http://www.example.com/* but not http://www.example.com/CDadmin/* I have tried the following: ...
2
votes
1answer
105 views

combined 301 redirects not working

I made some changes to the files on a website and now Search Console is showing me 404 errors for some URLs. The normal setup, which works fine is like this: the user-friendly URL mywebsite.com/...