Mod Rewrite and 404 Error - regex

At the moment the users of my website can access files with the following url-schema:
http://www.example.com/dwl/download.php?file=/files/index.rar
Now i want that they can access it with the following schema:
http://www.example.com/dwl/content/files/index.rar
The download.php file is within the dwl directory.
I tried the following .htaccess:
RewriteEngine On
RewriteRule ^file/([^/]*)$ download.php?file=$1 [L]
But when i try it, i get a 404-Error.
Can anybody please help me to write the correct .htaccess-Entry?

If you want to redirect from http://www.example.com/dwl/download.php?file=/files/index.rar to http://www.example.com/dwl/content/files/index.rar, you need this:
RewriteRule ^/dwl/download.php?file=/(.*) /dwl/content/$1 [L]

I think the code you have to use is the following :
RewriteEngine On
RewriteRule ^/dwl/content(/files/[^/]*)$ /dwl/download.php?file=$1

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

Related

Making user-friendly URL using .htaccess

I need to make my websites link user friendly. Currently, they look like this:
mydomain.com/post.php?title=News-Feeds-Latest-Addition-Puts-facebook-news-26
I want to make them look like this:
mydomain.com/title/get-back-your-recycle-bin-IT-news-85.html
I've written the following code into my .htaccess file:
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^title/([^/]*)\.html$ /post.php?title=$1 [L]
I don't know why, but it doesn't work. How can I get it to work?
You can use this code
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{THE_REQUEST} \s/post\.php\?(title)=([^\s&]+) [NC]
RewriteRule ^ /%1/%2.html? [R=302,L]
RewriteRule ^(title)/([^.]+)\.html$ /post.php?$1=$2 [L]
Use this :
RewriteEngine on
RewriteRule ^title/get-back-your-recycle-bin-IT-news-85.html/?$ post.php?title=News-Feeds-Latest-Addition-Puts-facebook-news-26 [NC]
now you can usethis url : mydomain.com/title/get-back-your-recycle-bin-IT-news-85.html

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]

mod_rewrite rule to change parent folder

Some unchangeable hyperlinks on a website point to /folderA/index.php?id=somestuff.
I need to redirect the Request to /folderB/index.php?id=somestuff instead.
I did some experimenting with this but I just can't get it to work, any help is appreciated.
RewriteEngine on
RewriteRule /folderA/index\.php\?id=([\w-]+)$ /folderB/index.php?id=$1
Keep in mind that RewriteRule doesn't match query string and matches only REQUEST_URI without it. Use this code instead:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+folderA/(index\.php\?id=[^&\s]+) [NC]
RewriteRule ^ /folderB/%1 [R=302,L]
Assuming that you are not planning on using different get request this should work:
RewriteEngine on
RewriteRule /folderA/index\.php\?id=(.*?)$ /folderB/index.php?id=$1

.htaccess mod_rewrite... I think?

I was wondering how in .htaccess I can redirect the following URL:
/mysite.com/blog/Something => /mysite.com/blog.php?tag=Something
Here is a script I've used on a different site however this is a bit simpilar:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^([a-zA-Z0-9]+)$ index.php?name=$1
RewriteRule ^([a-zA-Z0-9]+)/$ index.php?name=$1
</IfModule>
Thanks in Advance
Just add this rule:
RewriteRule ^blog/(.*)$ blog.php?tag=$1 [L,QSA,NC]
Update: As per your comment this is the rule you will need:
RewriteRule ^blog/([^/]*) blog.php?tag=$1 [L,QSA,NC]
Try adding the following to the .htaccess file in the root directory of your site.
RewriteEngine on
RewriteBase /
#/mysite.com/blog/Something to /mysite.com/blog.php?tag=Something
RewriteRule ^blog/(something)$ blog.php?tag=$1 [L,NC,R=301]
If something is a variable then change the rule to
RewriteRule ^blog/(\w+)$ blog.php?tag=$1 [L,NC,R=301]
If you want the URL to stay the same in the Users browser then drop the R=301 as below
RewriteRule ^blog/(\w+)$ blog.php?tag=$1 [L,NC]