.htaccess mod_rewrite... I think? - regex

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]

Related

When i add forward slash after blog then it's not working

<IfModule mod_rewrite.c>
RewriteEngine on # Turn on the rewriting engine
RewriteRule ^blog-([a-zA-Z0-9_-]+)$ blog_detail.php?id=$1
</IfModule>
Basically I want URL Something Like - http://www.hostname.org/blog/anything
But now show - http://www.hostname.org/blog-anything (It's work properly)
Please help!
From what I understand of your question:
RewriteEngine On
RewriteRule ^blog-([\w-]+)$ /blog/$1 [R=301,L,NC]
RewriteRule ^blog/([\w-]+)/?$ /blog_detail.php?id=$1 [L,NC]

htaccess Mod Rewrite home.php to be removed

I have an index.php page which has a redirect on to go to home.php
is there anyway using htaccess i can make home.php be hidden so the user just see's the domain name in the address bar?
Yes sure you can use this rewrite rule in your DOCUMENT_ROOT/.htaccess file:
DirectoryIndex index.php
RewriteEngine On
RewriteCond %{THE_REQUEST} /index\.php [NC]
RewriteRule ^(.*?)index\.php$ /$1 [L,R=302,NC,NE]

Mod Rewrite and 404 Error

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]

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]

URL rewrite and RegExp

I want the URL rewrite to result in this:
test.php?site=hi --> www.domain.com/hi
test.php?site=hi&id=1 --> www.domain.com/hi/1
test.php?site=hi&cmd=test --> www.domain.com/hi/test
test.php?site=hi&cmd=test&id=1 --> www.domain.com/hi/test/1
I have tried this, but it doesn't work. I am new at regular expressions, so there might be place for corrections:
RewriteRule ^([a-zA-Z]+)/?+([0-9]+)?/? test.php?site=$1&id=$2
RewriteRule ^([a-zA-Z]+)/?+([a-zA-Z]+)?/?+([0-9]+)?/? test.php?site=$1&cmd=$2&id=$3
How should the RewriteRule be?
Thanks in advance.
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 /
RewriteRule ^([^/]+)/([a-z]+)/(\d+)/?$ /test.php?site=$1&cmd=$2&id=$3 [L,NC,QSA]
RewriteRule ^([^/]+)/([a-z]+)/?$ /test.php?site=$1&cmd=$2 [L,NC,QSA]
RewriteRule ^([^/]+)/(\d+)/?$ /test.php?site=$1&id=$2 [L,QSA]
RewriteRule ^([^/]+)/?$ /test.php?site=$1 [L,QSA]