mod rewrite for pretty urls and also hide index.php - regex

How can i mod-rewrite to obtaining a pretty url like below
example.com
contains a form to get a text value and pass it another file for processing that file is in directory as web but i need to change that as pretty urls
example.com/web/index.php?url=mydomain.com
to
example.com/web/mydomain.com
example.com/web/newdomain.com

Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+web/index\.php\?url=([^\s&]+) [NC]
RewriteRule ^ /web/%1? [R=301,L,NE]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^web/(.+?)/?$ /web/index.php?url=$1 [L,QSA]

Related

.htaccess: Redirect all pages except one

I'm trying to setup my .htaccess file to redirect from oldsite.com to newsite.com, with just one exception: If the user visits http://oldsite.com/cal then I want it to display the cal.html file in the root directory.
Here's the current .htaccess file that I've got (which doesn't work):
Options +FollowSymlinks -MultiViews
RewriteEngine On
# this page can be served .. (not working)
RewriteRule /cal http://oldsite.com/cal.htm [L,NC]
# .. but rewrite everything else (this works fine)
RewriteCond %{HTTP_HOST} ^(www\.)?oldsite\.com [NC]
RewriteRule ^(.*) http://newsite.com/$1 [R=301,L,NC]
What do I mean by it doesn't work? Well, it just redirects http://oldsite.com/cal to http://newsite.com/cal instead of displaying http://oldsite.com/cal.html
Change it to this:
Options +FollowSymlinks -MultiViews
RewriteEngine On
RewriteRule ^cal/? cal.htm [L,NC]
RewriteCond %{HTTP_HOST} ^(www\.)?oldsite\.com [NC]
RewriteRule ^ http://newsite.com%{REQUEST_URI} [NE,R=301,L]
Notes
if oldsite and newsite live on different servers, you don't even need the RewriteCond.
you could also invert the order of the rules, in which case the main rule would be RewriteRule ^(?!cal/?$) http://newsite.com%{REQUEST_URI} [NE,R=301,L]

Rewrite rule to an other domain keeping rest of url

This is what I need to do:
website EXAMPLE with url
/?VVWM=$59095-K9T-50U00-VX0U**|jDDQvcZbTESbGqI2AJ8Iww|dIWecCGiGUive6I2AJ8Iww||||1|0$&utm_source=followup-offerte&utm_medium=email&utm_campaign=VVWM
has to redirect to:
http://www.sluitsnel.nl/goedkope-scooterverzekering/?VVWM=$59095-K9T-50U00-VX0U**|jDDQvcZbTESbGqI2AJ8Iww|dIWecCGiGUive6I2AJ8Iww||||1|0$&utm_source=followup-offerte&utm_medium=email&utm_campaign=VVWM
So the indication for this redirection is:
http://www.goedkope-scooterverzekeringen.nl/?VVWM=$59095-K9T-50U00-VX0U
Thanks in advcance!
Greetings,
Ivar
Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^(www\.)?goedkope-scooterverzekeringen\.nl$ [NC]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+\?(VVWM=$59095-K9T-50U00-VX0U[^\s]*) [NC]
RewriteRule ^ http://www.sluitsnel.nl/goedkope-scooterverzekering/?%1 [R=301,L,NE]

htaccess redirect file request of one to another file

I need modificate file request http://subdomain.site.com/file.txt -> http://site.com/file-subdomain.txt
Please help with htaccess code. Thanks!
Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^(subdomain)\.(site\.com)$ [NC]
RewriteRule ^file\.txt$ http://%2/file-%1.txt [L,R=301,NC]
EDIT:
RewriteCond %{HTTP_HOST} ^(subdomain)\.(site\.com)$ [NC]
RewriteRule ^file\.txt$ /file-%1.txt [L,NC]

redirect via htaccess where IP is not && remove index.php

I usually use this htaccess file to remove index.php from my URLs in ExpressionEngine
AddType video/ogg .ogv
AddType video/mp4 .mp4
AddType video/webm .webm
AcceptPathInfo On
Options -Indexes
<IfModule mod_rewrite.c>
RewriteEngine On
Options +FollowSymLinks
# Looks for files and directories that do not exist
# and provide the segments to the index.php file
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^/index.php
RewriteCond $1 !.(css|js|png|jpe?g|gif|ico)$ [NC]
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
While that works great, before we move this site into production, we're directing all traffic to the given url to another via this htaccess file
RewriteEngine On
RewriteBase /
RewriteCond %{REMOTE_ADDR} !^127\.0\.0\.1
RewriteRule ^(.*)$ http://www.anotherdomain.com/ [R=301,NC]
My own ip address is replacing the localhost call so that I can access the site.
Basically what I'm looking for is a combination of these 2 that will remove index.php from my URLs for me but still redirect everyone else.
Thanks,
Steven
Found that this works great:
RewriteEngine on
# If your IP address matches any of these - then dont re-write
RewriteCond %{REMOTE_ADDR} !^127\.0\.0\.1
RewriteRule ^(.*)$ http://www.anothersite.com/ [R=302,L]
# do not rewrite links to the assets and theme files
RewriteCond $1 !^(assets|themes|images)
# do not rewrite for php files in the document root, robots.txt etc
RewriteCond $1 !^([^\..]+\.php|robots\.txt|crossdomain\.xml)
# but rewrite everything else
RewriteRule ^(.*)$ index.php/$1 [L]

.htaccess in root and subfolder, each to redirect to own index.php

I apologise for a seemingly duplicate question, but none of the dozens I've looked at actually had the same problem.
I have the following directory structure:
/.htaccess
/index.php
/subfolder/.htaccess
/subfolder/index.php
I'd like all requests for pages to be handled by /index.php, unless the request starts /subfolder in which case it should be handled by /subfolder/index.php
e.g. /abc to be rewritten to /index.php?u=abc
e.g. /subfolder/def to be rewritten to /subfolder/index.php?u=def
I've been going round in circles over this, so any help will be massively appreciated.
EDIT: forgot to mention the problem!
Requests within the subfolder are handled by the root index.php, not the subfolder one. (Except requests for /subfolder)
Current File contents
/.htaccess
Options -Indexes -MultiViews +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !^/admin
RewriteRule ^(.*)$ /index.php?u=$1 [NC,QSA]
/subfolder/.htaccess
RewriteBase /admin/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /admin/index.php?u=$1 [NC,QSA]
Have your root .htaccess like this:
Options -Indexes -MultiViews +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(?!admin/)(.+)$ /index.php?u=$1 [NC,QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^admin/(.+)$ /admin/index.php?u=$1 [NC,QSA,L]
There is no need to have .htaccess in admin folder for this simple requirement.
This line of the root folder .htaccess:
RewriteRule ^(.*)$ /index.php?u=$1 [NC,QSA]
is causing all the requests to non-existent filepaths to be redirected to the root folder's index.php. That's the problem.
One possible solution could be to substitute the above line with this couple of lines:
RewriteRule ^subfolder/(.*)$ /subfolder/index.php?u=$1 [L,NC,QSA]
RewriteRule ^(.+)$ /index.php?u=$1 [L,NC,QSA]
By adding the L (last) flag and writing the rules in this order you'll get Apache to redirect correctly your requests, and eliminate the need for rewriting directives into /subfolder/.htaccess .