Menu
  • HOME
  • TAGS

Convert .htaccess to nginx, seeking working solution

apache,.htaccess,mod-rewrite,nginx

First of all, you have to understand what this .htaccess do. Except of incomplete rewrite this .htaccess tries to serve precompressed assets (file.css.gz instead of file.css) and rewrites requests for non-existent files to index.php. I would write something like this: location / { try_files $uri $uri/ /index.php; } location ^~...

Redirecting to rewritten URL

.htaccess,mod-rewrite

Try this instead: RewriteEngine On RewriteRule ^$ /welcome [R=302,L] RewriteRule ^welcome$ /index.html [L] First line redirects a request made to the root to /welcome. Second rule internally rewrites /welcome to index.html....

Rewriting with .htaccess doesn't work

regex,apache,.htaccess,mod-rewrite

Try this code in root .htaccess: Options +FollowSymLinks -MultiViews RewriteEngine On # to convert spaces to hyphens RewriteRule "^(pdf)/(\S*) +(.*)$" /$1/$2-$3 [L,NE,R=302] RewriteRule ^(pdf/.+)$ /pdf.php?file=$1 [L,QSA,B,NC] ...

redirect and php in htaccess

php,apache,.htaccess,mod-rewrite

Seems register_globals is the issue. http://php.net/manual/en/security.globals.php Add following line at the top: $id = $_GET['id']; ...

Mod rewrite prevening to acces a link

php,apache,.htaccess,mod-rewrite

What I mean by prepend, is use a name so that it will match the rule specifically. Like the word shop. Something like this. RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^shop/([^/]+)/([^/]+)/([^/]+)\.php$ /shop.php?id_cat=$1&id=$2&subcat=$3 [L] Then you can use a URL like this and it won't interfere with your...

Rewrite folders and Remove the trailing slash at the end

php,apache,.htaccess,mod-rewrite

You need to redirect the trailing slash URL's instead of just rewriting them. You also probably need to add some conditions to the rules: RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)/$ /$1 [L,R=301] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^([^/]+)$ /includes/category.php?url=$1&pageType=category [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond...

.htaccess rewrite condition to remove 'www' from 'https://www'

.htaccess,mod-rewrite

i'm sure this is a duplicate but here the code i use: RewriteEngine on #This removes the www. RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC] RewriteRule ^(.*)$ http://%1%{REQUEST_URI} [L,R=301,NC,QSA] #This makes redirect to https RewriteCond %{HTTPS} off RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L] ...

URL Rewrite with .htaccess From /user/projects/index.php?project_id=1 to /user/projects/1

apache,.htaccess,mod-rewrite

You can use this rule in your /user/projects/.htaccess. RewriteEngine On RewriteBase /user/projects RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^([0-9]+)/?$ index.php?project_id=$1 [NC,L] From the root you can do. RewriteEngine On RewriteBase / RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\ /+user/projects/index\.php\?project_id=([^&\ ]) RewriteRule ^ %1? [R=301,L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^user/projects/([0-9]+)/?$...

htaccess rewrite doesn't work when path has same name as file

php,regex,apache,.htaccess,mod-rewrite

You need to place this line on top of your .htaccess to turn off MultiViews option: Options -MultiViews Option MultiViews is used by Apache's content negotiation module that runs before mod_rewrite and makes Apache server match extensions of files. So /file can be in URL but it will serve /file.php....

.HTAccess - How to modify a url with under score in file name as sub directory?

regex,apache,.htaccess,mod-rewrite

You can use a new rule for underscore condition: RewriteEngine on RewriteRule ^en-gb/([^/]+)/([^/.]+)/?$ /site/views/en/gb/$1_$2.html [L,NC] RewriteCond %{REQUEST_FILENAME} -f [OR] RewriteCond %{REQUEST_FILENAME} -d RewriteRule ^ - [L] RewriteCond %{DOCUMENT_ROOT}/$1\.html -f RewriteRule ^(.+?)/?$ $1.html [L] RewriteCond %{DOCUMENT_ROOT}/$1\.php -f RewriteRule ^(.+?)/?$ $1.php [L] RewriteRule ^en-gb(.*)$ /site/views/en/gb/$1 [L,NC] ...

htaccess rewrite url parameter

php,apache,.htaccess,mod-rewrite,url-rewriting

You can use this code in your /myproject/.htaccess file: RewriteEngine On RewriteBase /myproject/ RewriteCond %{QUERY_STRING} ^supplier=([^&]+) [NC] RewriteRule ^/?$ ?product_cat=%1 [L,R=301] ...

Htaccess regex: exclude REQUEST_URI

regex,apache,.htaccess,mod-rewrite,redirect

Try this rule instead: RewriteCond %{HTTP_HOST} ^sub\.example\.com$ [NC] RewriteCond %{THE_REQUEST} !\s/+(aaa|bbb|ccc)/ [NC] RewriteRule . http://www.example.com%{REQUEST_URI} [R=301,L,NE] Test it after clearing your browser cache. Using THE_REQUEST instead of REQUEST_URI to make sure we use unchanged URI values as received by Apache....

.htacces rewrite by cookie value

apache,.htaccess,mod-rewrite,cookies,url-rewriting

Try this : RewriteEngine On #Redirecting with the cookie value RewriteCond %{HTTP_COOKIE} ^lang=(en|es)$ [NC] RewriteRule ^(.*)$ http://example.com/%1/$1 [R,L] If the cookie is set to "en" this will redirect every requests to example.com/en/...

Is it possible to allow only the correct pretty url?

php,apache,.htaccess,mod-rewrite,friendly-url

You can have a new rule for that: RewriteEngine On RewriteBase /app/ RewriteRule ^([a-z]+)/([a-z]+)/?([0-9]*)$ index.phpcontroller=$1&action=$2&id=$3 [NC,L,QSA] # If the request is not for a valid directory RewriteCond %{REQUEST_FILENAME} !-d # If the request is not for a valid file RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^ index.php [L] ...

Htaccess: HTTPS redirection on page + sub pages

apache,.htaccess,mod-rewrite,redirect,https

# HTTPS page Redirects RewriteEngine On # This will enable the Rewrite capabilities RewriteCond %{HTTPS} !=on # This checks to make sure the connection is not already HTTPS RewriteRule ^/?enrolments/(.*) https://%{SERVER_NAME}/enrolments/$1 [R,L] #END https redirects ...

Redirect non-www to www except subdomains by .htaccess

regex,apache,.htaccess,mod-rewrite

You can use this rule: RewriteCond %{HTTP_HOST} ^[^.]+\.com(\.au)?$ [NC] RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1 [R=301,L] ...

change request filename (%{REQUEST_FILENAME}) to new path in .htaccess

regex,apache,.htaccess,mod-rewrite

You can tweak your rules like this: RewriteEngine On RewriteBase /core/ #Check if file exist in original path (/var/www/html/core): RewriteCond %{REQUEST_FILENAME} -s [OR] RewriteCond %{REQUEST_FILENAME} -l [OR] RewriteCond %{REQUEST_FILENAME} -d RewriteRule ^ - [L] #try new path (/var/www/html/core/latest): RewriteCond %{DOCUMENT_ROOT}/core/latest/$1 -f RewriteRule ^((?!latest/).*)$ latest/$1 [L,NC] RewriteCond %{DOCUMENT_ROOT}/core/latest/$1 -f makes sure...

Particular URL redirect to http if request come from particular host

apache,http,mod-rewrite,ssl,url-rewriting

You should add another RewriteCond to exclude redirect for this IP: RewriteCond %{SERVER_PORT} =80 RewriteCond %{REMOTE_ADDR} !=10.1.2.3 RewriteRule ^(.*) https://%{SERVER_NAME}%{REQUEST_URI} [R,L] ...

.htaccess RewriteRule regex match specific words

regex,.htaccess,mod-rewrite

It may help: RewriteRule ^(apple|orange)/$ /product.php?prod=$1 [L]...

How do I redirect a URL with a parameter to a clean URL in htaccess?

.htaccess,mod-rewrite,redirect

Add question sign after to remove query string RewriteRule ^news/news\.php$ /posts/vanity-url.php? [L,R=301] ...

Is it possible to do a “reverse” mod_rewrite?

.htaccess,mod-rewrite

You can use this in your .htaccess to do the reverse. RewriteEngine On RewriteCond %{THE_REQUEST} [A-Z]{3,}\ /product\.cgi\?id=([^&\ ]+) RewriteRule ^ /id/%1? [R=301,L] RewriteRule ^id/([^/]*)$ /product.cgi?id=$1 [L] ...

htaccess rewrite rule is not working

php,apache,.htaccess,mod-rewrite,redirect

Try this in your root .htaccess: Options +FollowSymlinks -MultiViews RewriteEngine on RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} -f [OR] RewriteCond %{REQUEST_FILENAME} -d RewriteRule ^ - [L] RewriteRule ^post/(.+)$ post.php?tag=$1 [L,NC,QSA] RewriteRule ^search/(.+)$ search.php?tag=$1 [L,NC,QSA] ...

unable to escape “?” in the url rewriting in htaccess

php,apache,.htaccess,mod-rewrite,url-rewriting

You can replace your rule by this rule: RewriteRule ^(spashop)/admin/([a-zA-Z]+)/?$ $1/index.php?url=spaAdminShop/$2\?%{QUERY_STRING} [L,NC] ...

Silly mod_rewrite issue

.htaccess,mod-rewrite

If there was no query string involved, RedirectMatch could be used (not sure why it was made to ignore that part of URLs, or maybe I am mistaken). Anyway, with mod_rewrite try this: RewriteCond %{REQUEST_URI}?%{QUERY_STRING} ^/ar/idea\.php\?permalink=(.*?)$ RewriteRule . /ar/%1? [R=301] This is assuming there is a RewriteEngine On directive present,...

Rewrite condition ! being ignored

regex,apache,.htaccess,mod-rewrite,redirect

There might be other rules in your .htaccess changing REQUEST_URI to something else and causing negation based condition to pass. Try this instead: RewriteCond %{THE_REQUEST} !/categoryOne RewriteRule ^ http://www.google.be/ [L,R=301] THE_REQUEST variable doesn't change its value after other rules....

Rewrite rules cause infinite redirect loop

apache,.htaccess,mod-rewrite,url-rewriting

The first RewriteRule never will be used because of RewriteCond. It always false. %{REQUEST_FILENAME} return full path on server, no filename. The second rule alone makes infinite loop redirecting /site/index.php to itself. If you explain what you want, we try to help youto make working htaccess UPDATE RewriteEngine on #...

Exclude a deep subdirectory from an .htaccess RedirectMatch

apache,.htaccess,mod-rewrite,url-rewriting

You can use a negative lookahead to exclude the subdirectory, like so: RedirectMatch 404 /directory(?!/sub/sub/sub/sub) You'll also notice that I've removed the check for the trailing slash or end of string. Reason being: directories always have trailing slash (unless DirectorySlash is set to off). Also, no need to check for...

How do I strip out ?_escaped_fragment_= using .htaccess

ajax,.htaccess,mod-rewrite,seo

This is how I rewrote it so that all ?_escaped_fragment_=/XXXXX requests got redirected to /XXXXX without the query RewriteCond %{QUERY_STRING} ^_escaped_fragment_=(.*)$ RewriteRule ^(.*)$ http://www.%{HTTP_HOST}%1? [L,R=301] This makes www.domain.com/?_escaped_fragment_=/somepage redirect (permanently) to www.domain.com/somepage ...which is just what I wanted....

Confused about Htaccess

php,apache,.htaccess,mod-rewrite

This is what you need to do. You can use this code in your .htaccess. RewriteEngine On RewriteBase /testwebsite/ #redirect index.php to the pretty URL RewriteCond %{THE_REQUEST} [A-Z]{3,}\ /testwebsite/index\.php RewriteRule ^ home? [R=301,L] #internally rewrite pretty URL to index file RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^home/?$ index.php [L]...

.htaccess hotlink protection - add image exception

.htaccess,mod-rewrite

You can use the following instead: RewriteEngine on # Check that the file exists RewriteCond %{REQUEST_FILENAME} -f # Check we're not being referred from our own domain RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?my-site\.com [NC] # Check that the request is not fot the hotlink image RewriteCond %{REQUEST_URI} !^/images/dontsteal\.png$ [NC] # If all the...

.htaccess Mod_Rewrite inconsistent

php,apache,.htaccess,mod-rewrite

Try this: Options -MultiViews RewriteEngine On #Working rules: RewriteRule ^privacy$ privacy.php [L] RewriteRule ^terms$ terms.php [L] RewriteRule ^team$ team.php [L] RewriteRule ^candidates$ candidates.php [L] RewriteRule ^clients$ clients.php [L] RewriteRule ^article/([^/]+)/?$ article.php?id=$1 [L,QSA] RewriteRule ^job/([^/]+)/?$ job.php?id=$1 [L,QSA] RewriteRule ^contact/([^/]+)/?$ contact.php?location=$1 [L,QSA] Option MultiViews is used by Apache's content negotiation module that...

.htaccess file making new domain redirect to my original domain

apache,.htaccess,mod-rewrite,redirect

Why not just exclude the new site, if I am understanding correctly? RewriteEngine On RewriteCond %{HTTP_HOST} !^(www\.)?newsite\.com [NC] RewriteCond %{HTTP_HOST} ^www\.oldsite\.com [NC] RewriteRule ^(.*)$ https://oldsite.com/$1 [R=301,NE,L] RewriteCond %{HTTPS} ^off RewriteCond %{HTTP_HOST} !^(www\.)?newsite\.com [NC] RewriteRule ^(.*) https://oldsite.com/$1 [R=301,NE,L] Alternatively maybe you can just tell it to not do anything based on...

SWF works locally but not loaded from server

mod-rewrite,unity3d,swf,swfobject

I did some further tests, sadly there are no errors on the console. But it pretty much looks like there's something wrong with your .swf file on the server, because when I download the file from your server it is not working locally either. (Did you try that before?) How...

Apache Rewrite to File System Or Proxy

apache,mod-rewrite

As it turns out, the statement "latter rule is always matched & the former is never matched" may not have been true; I had a confusing httpd.conf in which rewrite logging was enabled in more than one place. In any event, the first rule was definitely incomplete. It should look...

Htaccess Code not working after changing Server

php,regex,.htaccess,mod-rewrite,http-status-code-301

To create exception for administrator folder you can do: RewriteRule ^(?!administrator/).+?(index\.php)$ /$1 [L,NC,R=301] ...

.htaccess URL-Rewrite solution?

apache,.htaccess,mod-rewrite,url-rewriting,rewrite

You can use this code in your /subfolder/search-brands/.htaccess file: RewriteEngine On RewriteBase /subfolder/search-brands/ RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^([^/]+)/([^/]+)/?$ index.php?q=$1&brand=$2 [L,QSA] ...

after using mod_rewrite link are not found

php,.htaccess,mod-rewrite

So you want the assets to be requested correctly? I guess you're using incorrect relative paths for linking those in your page's code (something like "images/image.jpg"..). If that's the folder structure you have, try to go one level up and use this path: <img src="../admin/images/image.jpg" ... or, in the case...

Redirect specific Url variables

php,.htaccess,mod-rewrite,redirect

Try this : RewriteEngine On RewriteCond %{QUERY_STRING} ^s=([^&]+)&type=([^&]+) [NC] RewriteRule ^data.php$ /d.php?s=%1&t=%2 [NC,R,L] This will externally redirect a request for : /data.php?s=foo&type=bar to /d.php?s=foo&t=bar ...

How to properly write a RewriteCond for https and subdomains

regex,apache,.htaccess,mod-rewrite,url-rewriting

Change your rules like this: RewriteEngine On RewriteCond %{HTTP_HOST} ^(purchase|booking)\.mydomain\.com$ RewriteCond %{HTTPS} off RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [NE,R=301,L] RewriteCond %{HTTP_HOST} =purchase.mydomain.com RewriteRule ^((?!purchase/).*)$ /purchase/$1 [L] RewriteCond %{HTTP_HOST} =booking.mydomain.com RewriteRule ^((?!booking/).*)$ /booking/$1 [L] http:// or https:// in target will redirect instead of rewriting. ...

Block all user-agents by htaccess except one

regex,apache,.htaccess,mod-rewrite,litespeed

Unfortunately, LiteSpeed does not support SetEnvIf* directives in .htaccess files. As an alternative, you'll need to use mod_rewrite: RewriteEngine On # Check that the request is for /bg.js RewriteCond %{REQUEST_URI} ^/bg.js # Check that the request matches an existing file RewriteCond %{REQUEST_FILENAME} -f # Check that the user agent does...

Remove index.php From Sub directory websites URL

php,.htaccess,laravel,mod-rewrite

Set a RewriteBase for the new folder, like so: RewriteEngine On RewriteBase /site1/ RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^ index.php [L] ...

.htaccess for language detection

php,apache,.htaccess,mod-rewrite

Well for this specific example. example.com/xxx/en i need index.php?lang=en&a=xxx You can use a rule like this. RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^([^/]+)/en/?$ /index.php?lang=en&a=$1 [L,QSA] ...

Block some internal urls using .htaccess in cakephp

regex,apache,.htaccess,mod-rewrite

You can use these rules: <IfModule mod_rewrite.c> RewriteEngine on # block these URIs RewriteRule (register|login) - [F,NC] RewriteRule ^$ app/webroot/ [L] RewriteRule (.*) app/webroot/$1 [L] </IfModule> ...

css and js files have 403 forbidden error after activating mod_rewrite

php,apache,codeigniter,mod-rewrite

Remove this and try again: <IfModule authz_core_module> Require all denied </IfModule> <IfModule !authz_core_module> Deny from all </IfModule> ...

PHP - .htaccess and GET parameters

php,regex,.htaccess,mod-rewrite,redirect

Try these rules: RewriteRule ^login/?$ ?i=l [L,QSA] RewriteRule ^login(&[^/]+)/?$ ?i=l$1 [L,NC] Though I suggest using: domain.com/login?redirect=/account/settings and get rid of 2nd rule altogether. QSA flag in first rule will add redirect=/account/settings query parameter as $_GET to your php file....

Rewrite non-dynamic pages using htaccess

apache,.htaccess,mod-rewrite

Try the following rules in your /htaccess file : RewriteEngine On RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/([^.-]+)\.php [NC] RewriteRule ^ %1/ [NC,R,L] RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/([^-]+)-([^.]+)\.php [NC] RewriteRule ^ %1/%2/ [NC,R,L] RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^([^/]+)/?$ $1.php [QSA,NC,L] RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^([^/]+)/([^/]+)/?$ $1-$2.php [QSA,NC,L] ...

mod_rewrite rule to drop the string with m=1 from the URL regardless of its location?

regex,apache,.htaccess,mod-rewrite

You can use this code in your DOCUMENT_ROOT/.htaccess file: RewriteEngine On RewriteCond %{QUERY_STRING} (^|&)m=1(&|$) [NC] RewriteRule ^ %{REQUEST_URI}? [L,R=302] (^|&)m=1(&|$) regex is to make sure m=1 is matched anywhere in query string....

Apache Mod rewrite not work for me When use (-) in url?

php,regex,apache,.htaccess,mod-rewrite

That is because your use of [^-] in your regex. Use this code: ErrorDocument 404 /404.php ErrorDocument 403 /403.php Options -indexes RewriteEngine on RewriteCond %{HTTP_HOST} ^example\.com RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L] RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI}.php -f RewriteRule ^(.*)$ $1.php [L] RewriteRule ^products/([^/]+)/([^/]+)/([^/]*)$ /products.php?produucts_name=$1&products_des=$2&products_id=$3 [L] ...

How to modrewrite in my subfolder

regex,apache,.htaccess,mod-rewrite,url-rewriting

Use this rule in /subfolder/.htaccess: RewriteEngine on RewriteBase /subfolder/ RewriteRule ^([^/]+)/([^/]+)\.html$ index.php?a=$1&u=$2 [L,QSA,NC] ...

Mod Rewrite - Disable it for specific folders

php,css,apache,.htaccess,mod-rewrite

But book.php file includes the CSS and JS files as www.domain.com/city/css and www.domain.com/city/js and hence comes up with the error 404. That I believe is due to your use of relative paths in including css and js files. For that you can add this in the <head> section of...

Rewrite url not working in htaccess

php,apache,.htaccess,mod-rewrite,url-rewriting

QUERY_STRING is only used to match query string without URI. You need to use: Options -MultiViews RewriteEngine On RewriteBase /mywbsite/ RewriteCond %{THE_REQUEST} /search_data\.php\?keywords=([^&]+)&f=([^\s&]+) [NC] RewriteRule ^ search/%1/%2? [R=301,L] RewriteRule ^search/([^/]+)/([^/]+)/?$ search_data.php?keywords=$1&f=$2 [QSA,L,NC] ...

Apache Virtual Host redirect just for servername

apache,mod-rewrite,virtualhost

This rule should work for you RewriteEngine on RewriteCond %{HTTP_HOST} =abc RewriteRule ^(.*)$ http://abc.xyz.com/$1 [R,L] ...

Rewrite Problen .htaccess Redirect 301

php,apache,.htaccess,mod-rewrite,redirect

From the mod_alias/Redirect documentation: Additional path information beyond the matched URL-Path will be appended to the target URL. "Additional path information" is somewhat vague, but I assume they are referring to the url parameter. Now, this should not affect functionality at all, so again I assume that you just don't...

How to remove the word 'index' in the url [.htaccess]?

.htaccess,mod-rewrite,redirect,url-rewriting,file-extension

You can use: RewriteEngine On RewriteCond %{THE_REQUEST} /index [NC] RewriteRule ^(.*?)index(?:\.html)?$ /$1 [L,R=301,NC] RewriteCond %{REQUEST_FILENAME} !-d RewriteRule (.*)/index$ $1/ [R=301,L,NC] RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.+?)/$ $1 [R=301,L] ...

A series of rewriterule without Last [L] Flag

regex,apache,.htaccess,mod-rewrite

First of all a very good question with lots of details. If you enable RewriteLog you will notice this is actually being caused by this line (when you request http://localhost/h/first/second URL): add path info postfix: /landingpage1.php/second There a bug raised specifically for this issue on Apache.org. This happens when you...

How can I .htaccess 301 redirect all pages/files (EXCEPT FOR ONE) to new domain?

regex,apache,.htaccess,mod-rewrite

Keep your first rule as: RewriteEngine On RewriteCond %{HTTP_HOST} ^(www\.)?olddomain\.com$ [NC] RewriteCond %{THE_REQUEST} !/googleverification\.html [NC] RewriteRule ^ http://www.newdomain.com%{REQUEST_URI} [L,R=301,NE] ...

Grouping file extensions for re-writing URL's [.htaccess]

.htaccess,mod-rewrite,url-rewriting,rewrite,file-extension

Unfortunately, this is not possible. The TestString part of RewriteCond can only contain a plain string, and allows for server variables (HTTP_REFERER, for example) and back-references ($1 and %1, for example). As such, you cannot include an expression in the TestString - only the CondPattern (the second part of RewriteCond)...

redirecting https://domain.com to https://www.domain.com

apache,.htaccess,mod-rewrite

You need an OR condition here: RewriteEngine on RewriteCond %{HTTPS} off [OR] RewriteCond %{HTTP_HOST} !^www\. [NC] RewriteRule ^ https://www.domain.com%{REQUEST_URI} [R=301,L,NE] ...

How to rewrite example.com/catelogue.php?page=3&cat1=fruit&cat2=apple with .htaccess

php,apache,.htaccess,mod-rewrite,url-rewriting

This should work. Try your rules this way. It works for me. Options +FollowSymlinks RewriteEngine on RewriteCond %{REQUEST_FILENAME} -f [OR] RewriteCond %{REQUEST_FILENAME} -d RewriteRule ^ - [L] RewriteRule ^catelogue/([^/]+)/([^/]+)$ catelogue.php?page=3&cat1=$1&cat2=$2 [NC,L] RewriteRule ^catelogue/?$ catelogue.php?page=3 [NC,L] RewriteRule ^home/?$ index.php?page=1 [NC,L] ...

mod_rewrite to force ssl in apache24

apache,mod-rewrite,ssl

I don't think it will work, it will ask for the authorization before the redirect to SSL. Instead you could put the Auth directives in a VirtualHost block corresponding to the SSL port (443). Also you don't really need mod_rewrite, but a simple Redirect directive. <VirtualHost *:80> ServerName www.domain.com Redirect...

URL Rewriting in php CodeIgniter using .htaccess

php,apache,.htaccess,codeigniter,mod-rewrite

I think the problem are the missing placeholders. Without the placeholders your stated URL http://www.mysite.pk/jobs/search/faisalabad/all-cats won't match. The correct route should look like this: $route["jobs/pakistan/(:any)"]="vacancies/search"; $route["search/pakistan/(:any)"]="vacancies/search"; This way both jobs/pakistan and search/pakistan are working. Edit This RewriteRule will have the same effect when put in the .htaccess file. RewriteRule ^jobs/search/(.*)?$...

mod_rewrite into subdirectory file from folder

php,apache,.htaccess,mod-rewrite

You can use this rule in /gt/.htaccess: Options +FollowSymlinks RewriteEngine On RewriteBase /gt/ RewriteRule ^/?$ gt.php [L] ...

RewriteRule not catching

.htaccess,mod-rewrite

You can't match against the query string (everything after the ?) in a rewrite rule, you need to match against the %{QUERY_STRING} variable in a condition: RewriteCond %{QUERY_STRING} ^page=11\.$ RewriteRule ^index\.php$ /index.php?page=11 [L,R=301] ...

rewrite URL from /index.php?page=about to /page/

php,apache,.htaccess,mod-rewrite

Oddly enough /new/home/ works but any other like /new/contact-us/ does not work. The only thing I can think of is /home/ is the only one without a '-' character in the url. Am I missing something in my .htaccess to account for this? You are absolutely missing something to...

.htaccess rewrite rule page not found

php,.htaccess,mod-rewrite

You can change your PHP code like this: $name = filter_input(INPUT_GET, 'name'); if ($result = $mysqli->query("SELECT * FROM pages WHERE name='$name'")) { if ( $result->num_rows == 0 ) { printf('404 / page Not Found'); exit; } else { while ($row = $result->fetch_assoc()) { echo $row['content']; } } } else {...

.htaccess - 301 redirect where the URL structures aren't identical

regex,wordpress,.htaccess,mod-rewrite,redirect

The way you are trying to capture substrings and inject them into the substitution string is totally wrong. Try this: RewriteRule ^([A-Za-z0-9\-]+)/([A-Za-z0-9\-]+)/(\d*)/?$ http://localhost/ats-new/$1/$2-$3 [R=301,NC,L] ...

How to redirect URL if it contains “?”?

.htaccess,mod-rewrite

? is part of QUERY_STRING and not REQUEST_URI, and so you cannot check it directly in the rule itself. You can check for the presence of the ? by checking either QUERY_STRING or THE_REQUEST: # Check that QUERY_STRING is not empty: RewriteCond %{QUERY_STRING} !^$ RewriteRule ^ http://google.com/ [P] # Check...

.htaccess rewrite for keeping a trailing variable

.htaccess,mod-rewrite

Try : RewriteEngine On RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/?directory-1/productorder\?i=([^&\s]+) [NC] RewriteRule ^ /directory2/%1? [NE,NC,R,L] Your rewriterule is not working because of the following reasons : 1) A leading slash in RewriteRule directive is not required if you are using apache version 2. 2) Query string is not a part of match in...

Friendly URL using .htaccess and PHP “include”

regex,apache,.htaccess,mod-rewrite,url-rewriting

You will need an additional router rule to forward all non-file and non-directories to index.php with a parameter p: RewriteEngine On RewriteBase / RewriteCond %{HTTP_HOST} !^www\. [NC] RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L] # If the request is not for a valid directory RewriteCond %{REQUEST_FILENAME} !-d # If the request is not...

Remove plus sign from url using .htaccess

php,regex,apache,.htaccess,mod-rewrite

You can add a new rule for +/- conversion: Options -MultiViews RewriteEngine On RewriteBase /indianrealitybytes/ RewriteCond %{THE_REQUEST} /search_advance\.php\?keywords=([^&]+)&f=([^\s&]+) [NC] RewriteRule ^ search/%1/%2? [R=301,L] RewriteRule ^([^+]*)\+(.*)$ $1-$2 [R=302,NE,L] RewriteRule ^search/([^/]+)/([^/]+)/?$ search_advance.php?keywords=$1&f=$2 [QSA,L,NC] ...

.htaccess rewrite - redirect pages

apache,.htaccess,mod-rewrite,redirect,rewrite

You can use this code in your DOCUMENT_ROOT/.htaccess file: Options -Indexes +FollowSymLinks RewriteEngine On RewriteBase / RewriteCond %{HTTPS} off RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{THE_REQUEST} !/search/ [NC] RewriteRule ^(.*)$ search/$1 [L,R] RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f <IfModule mod_php5.c> RewriteRule ^(.*)$ index.php/$1 [L] </IfModule>...

Match last occurence of 4 digits htaccess rewrite

regex,.htaccess,mod-rewrite

I would use this rule: RewriteRule ^(.*)\/(.*)-(\d{4})(?:-(.*))?$ album.php?artist=$1&album=$2&releaseyear=$3&EXTRA=$4 Try it...

Redirect only non-existing sub-directories to another domain using wildcard

apache,.htaccess,mod-rewrite,redirect

This should work in your .htaccess file on example.com. RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^([^/]+)/?$ http://example2.com/$1 [R=302,L] Change to R=301 when you confirm it's working. ...

htaccess URL Rewrite - Root to Subfolder (with folder of the same name)

regex,apache,.htaccess,mod-rewrite,url-rewriting

Create /blog/.htaccess if it doesn't already exist and place this rule: RewriteEngine On RewriteBase /blog/ RewriteRule ^/?$ blog.html [L] # To internally forward /blog/file to /blog/file.html RewriteCond %{DOCUMENT_ROOT}/blog/$1\.html -f [NC] RewriteRule ^(.+?)/?$ $1.html [L] ...

Creating SEO friendly URLs using apache mod_rewrite

php,regex,apache,.htaccess,mod-rewrite

You can do: <ifModule mod_rewrite.c> # Turn on the engine: RewriteEngine on # Redirect certain paths to index.php: RewriteRule ^(search|contact)/?$ index.php?p=$1 [L,QSA,NC] RewriteRule ^([\w-]+)/([\w-]+)/?$ index.php?p=$1&user=$2 [L,QSA,NC] </ifModule> ...

.htaccess | Too many redirects

apache,.htaccess,mod-rewrite,redirect

I'm assuming that you are trying to do two things here: Force HTTPS and www. Redirect to test.php if a certain IP is making the request The issue you were facing was due to the fact that even though the IP address was being matched, it was still being checked...

Allow space and other special characters in htaccess url rewrite

php,regex,apache,.htaccess,mod-rewrite

You can tweak your regex like this: RewriteRule orderprod_cntr/([^/]+)/([^/]+)/?$ controller/orderprod_cntr.php?id1=$1&id2=$2 [L,QSA] ...

Redirecting and rewritting multiple urls with htaccess

php,apache,.htaccess,mod-rewrite,redirect

I have resolved my problem migrating my "spaghetti code" to a Laravel framework, and using the file routes.php to pass the variables and blade templates for minimizing the use of this variables.

How to redirect domain with www or without www

php,.htaccess,mod-rewrite,redirect

Just use this. Replace example.com with your domain. RewriteEngine on RewriteCond %{HTTP_HOST} ^example\.com [NC,OR] RewriteCond %{HTTPS} !^on RewriteRule ^ https://www.example.com%{REQUEST_URI} [R=301,L] ...

mod-rewrite to remove a folder

apache,.htaccess,mod-rewrite

Your rule is backwards - it works the other way around. You can try with the following: RewriteRule ^folder1/folder2/(.*)$ /demo/folder1/$1 [R,L] Or perhaps you'd like to make folder1 dynamic: RewriteRule ^([^/]+)/folder2/(.*)$ /demo/$1/$2 [R,L] If one of these works for you, and you would like to make the redirect permanent, you...

redirect one domain to the other while removing a subdirectory from the uri

.htaccess,mod-rewrite,http-status-code-301

You need to add a grouping in your regex and backreference in the redirect: RewriteEngine On RewriteCond %{HTTP_HOST} (^|\.)sub\.domain1\.com$ [NC] RewriteRule ^somefolder/(.*)$ https://domain2.com/$1 [R=301,L] And you don't need the condition to check the request URI, since you're already doing that in the rule's regex....

How to remove subdirectory using rewriterule with non-www redirection

regex,apache,.htaccess,mod-rewrite,redirect

You can use an OR condition in conditions: Options +FollowSymlinks RewriteEngine On RewriteCond %{HTTP_HOST} ^www\. [NC,OR] RewriteCond %{THE_REQUEST} /subdir/ [NC] RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC] RewriteRule ^(?:subdir/)?(.*)$ http://%1/$1 [NC,R=302,L] ...

how to pass %{THE_REQUEST} to a php file with htacess

php,regex,.htaccess,mod-rewrite

You are already passing it, but just don't use $_GET. Try this. RewriteEngine on RewriteRule . /process.php [L,NE] Then in PHP print_r($_SERVER["REQUEST_URI"]); Then you can explode on /....

mod_rewrite - force redirecting to rewritten URL

apache,.htaccess,mod-rewrite,redirect

You need a new rule for that redirect: Options +FollowSymLinks -MultiViews RewriteEngine On RewriteBase / RewriteCond %{THE_REQUEST} /(?:index\.php)?\?search=([^\s&]+) [NC] RewriteRule ^ search/%1? [R=302,L,NE] RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^search/(.*)$ /?search=$1 [L,QSA] ...

Pattern matching in htaccess rewrite condition

apache,.htaccess,mod-rewrite,https

You need to tell the RewriteCond what to match !/go/ against. Change the second line to: RewriteCond %{REQUEST_URI} !/go/ [NC] ...

adding a question mark to the url in url rewrite in .htaccess

php,apache,.htaccess,mod-rewrite

RewriteRule does not accept query. Use RewriteCond RewriteEngine on RewriteCond %{QUERY_STRING} (\w.+)-(\w.+) RewriteRule ^pass/$ view/pass.php?useremail=%1&actcode=%2 [L] ...

Apache does NOT search parent folders for .htaccess

.htaccess,mod-rewrite,apache2

The problem is that the RewriteRule assumes root is the location of .htaccess, not the current folder. The following code solves my question. RewriteOptions inherit RewriteEngine On RewriteRule /?$ example.php This post helped me: .htaccess RewriteRule not working in subdirectory...

301 Redirect entire site to new site using .htaccess file

.htaccess,mod-rewrite,redirect,http-status-code-301,http-redirect

You can get rid of all the code in your .htaccess and use this rule instead: RewriteEngine on RewriteRule ^ http://siteTWO.co.uk/? [R=301,L,NE] Make sure to clear your browser cache before testing this....

.htaccess mod_rewrite not consistent

php,apache,.htaccess,mod-rewrite

As mention in my comment, it will work if you shuffle your rules from bottom to top. Possible reason could be conflicting rules. So your .htaccess should look like, RewriteEngine On RewriteRule ^privacy/?$ privacy.php [L] RewriteRule ^terms/?$ terms.php [L] RewriteRule ^login/?$ loginregister.php [L] RewriteRule ^register/?$ loginregister.php [L] RewriteRule ^member/([^/]*)$ member.php?id=$1...

.htaccess SEO Friendly URLs not working with two parameters

php,apache,.htaccess,mod-rewrite,url-rewriting

1st and 2nd rule cannot coexist because they are matching same URI pattern. Only first will all the time. Tweak your rules like this: RewriteEngine on RewriteRule ^(shows)/([a-z_-]+)/?$ index.php?switch=$1&shows=$2 [NC,L,QSA] RewriteRule ^(news)/([a-z_-]+)/?$ index.php?switch=$1&article=$2 [NC,L,QSA] RewriteRule ^(shows|news|articles)/?$ index.php?switch=$1 [NC,L,QSA] ...

Redirection loop (URL rewriting)

regex,apache,.htaccess,mod-rewrite,rewriting

I suggest not using .php in pretty URL, make it extension-less. Try these rules in v2/.htaccess: RewriteEngine On RewriteBase /v2/ RewriteCond %{THE_REQUEST} /message\.php\?ID2=([^&\s]+) [NC] RewriteRule ^ message-%1? [NE,R=302,L] RewriteRule ^message-(.+)/?$ message.php?ID2=$1 [L,QSA,NC] ...

How to enable mod_rewrite on Apache 2.4?

php,wordpress,apache,mod-rewrite,centos7

i found the way to know if a module is loaded or not, here's to command to list the modules enabled: apachectl -M | sort It will list all enabled modules alphabetically. Wordpress has an .htaccess but default where it enables Rewrite_Mod for its use: # BEGIN WordPress <IfModule mod_rewrite.c>...

Why is RewriteRule bad flag delimiters?

php,apache,.htaccess,mod-rewrite

Remove space before $ to make it RewriteRule ^.*startAd/(.*)$ /post-ad-step-2.php?adType=$1 [L,QSA] ...

HTACCESS 301 redirect issue with strange url variables

wordpress,apache,.htaccess,mod-rewrite,redirect

Try just: RewriteRule ^&force= / [L,NC,R=301] ...

How can I redirect all visitors to a subdirectory but still have access to the root directory for development

regex,apache,.htaccess,mod-rewrite,redirect

You can use this code in your DOCUMENT_ROOT/.htaccess file: RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{QUERY_STRING} !(^|&)dev=1(&|$) [NC] RewriteRule !^maintenance\.html$ maintenance.html [L,NC] Key is use of query parameter dev=1. Without this query parameter site will show maintenance.html. But if you add ?dev=1 to your URL then you...

Create php variable from URL without get

php,.htaccess,mod-rewrite

You have no choice but to use rewrite for this That's what it's for. But I already have some htaccess rewrites (JOOMLA), and it is just for the only folder.. This absolutely does not matter. Your Apache setup can contain as many rewrites as you need. I've seen 100's. So...

.htaccess root changed with mod_rewrite

.htaccess,mod-rewrite,root

RewriteCond %{REQUEST_FILENAME} !-f makes sure existing files are not rewritten hence images/css/js files won't be routed to index.php. However your problem seems to be use of relative paths for images/css/js. Make sure to use absolute path in your css, js, images files rather than a relative one. Which means you...

htaccess rewrite rules conflict

php,.htaccess,url,mod-rewrite

Your issue is that the first rule matches, the last one can never get applied... RewriteEngine on RewriteRule ^gallery/([0-9]+)/?$ gallery.php?id=$1 [NC,L] RewriteRule ^([0-9a-zA-Z_-]+)/([0-9]+)$ products.php?cat=$1&id=$2 [NC,L] RewriteRule ^([^/]*)/([0-9a-zA-Z_-]+)/([0-9]+)$ product_categories.php?cat=$2&id=$3 [NC,L] RewriteRule ^(.*)/(.*)/([0-9a-zA-Z_-]+)/([0-9]+)$ product_details.php?cat=$3&id=$4 [NC,L] Rule of thumb: first the specific exceptions, then the more general rules. The NC flag does not...

mod_rewrite with two parameters

.htaccess,mod-rewrite

Remove leading slash from RewriteRule. It doesn't receive it. And doesn't receive Query string. Ifqp is present, QSA will save it. Must be enough: RewriteEngine on RewriteRule ^css/(.*).css$ /build/css.php?request=$1 [QSA] ...