.htaccess redirect all .html pages to process.php with get parameter - mod-rewrite

I want to redirect all links that have .html extension to a process.php file with directory + page name as get parameter. I have tried these link1 link2 solution but it does not work.
for e.g
http://localhost/Site/directory1/test1.html
http://localhost/Site/directory2/test2.html
to redirected to process.php as
http://localhost/Site/process.php?directory1/test1.html
http://localhost/Site/process.php?directory2/test2.html
I have tried like this.
RewriteEngine on
RewriteRule ^/(.*).html /process.php?page=$1
and this
RewriteCond %{REQUEST_URI} \.html$
RewriteRule ^(.*/)?([^/]*)\.php$ /process.php?page=$2 [R=301,L]
but it does not work.
Please see and suggest any possible way to do this.

Try this:
RewriteEngine on
RewriteRule ^([^/]*)/(.*\.html) /$1/process.php?page=$2 [R=301,L]

Your second example is very close to what I believe your looking for. Your just off by one directory and your looking for .php when you should be looking for .html. Give this a try.
RewriteEngine on
RewriteBase /
RewriteRule ^/(.*)/(.*)/(.*)\.html$ /Site/process.php?$2/$3 [R=301, L]

This should do(assuming that the .htaccess file lives in the Site directory):
RewriteEngine On
RewriteCond %{REQUEST_URI} \.html$
RewriteRule ^(.*?/)?(.*)$ /$1/process.php?page=$2 [R=301,L]

Related

Rewrite Rule not taking effect

I am trying to rewrite some URLs using my .htaccess file and the following syntax:
RewriteEngine On
RewriteRule ^movie/([0-9]+)/$ movie.php?id=$1
Basically, the URL http://screeningapp.co.uk/movie.php?id=771316320 should be rewritten to http://screeningapp.co.uk/movie/771316320, but that's not happening and I'm not sure why.
Thanks!
RewriteEngine On
RewriteRule ^movie/([0-9]+)/?$ /movie.php?id=$1 [L,nc]
#if you wanna redirect movie.php?id=1 to movie/1/
RewriteCond %{QUERY_STRING} ^id=([0-9]+)($|&)
RewriteRule ^movie.php$ /movie/%1? [R=301,L,NC]

Domain Url Rewrite

What I'm looking to do is rewrite the url so that one of the directories are hidden. For example;
http://www.example.com/home/example.html
to
http://www.example.com/example.html
As I'm new to .htaccess and mod_rewrite, is this something that can be done?
This should work:
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/home/.*$
RewriteRule ^(.*)$ /home/$1 [L]
Something like this should work.
RewriteEngine On # Turn on the rewriting engine
RewriteRule ^example.html$ /home/example.html [NC,L]

Creating SEO friendly URLs with htaccess

when I change the link It shows me an error page. maybe there is a problem with my website what do you think?
There is the url in my website: www.mywebsite.com/picture.php?1
and I want to change it to something like this: www.mywebsite.com/picture/1
here is my .htaccess
RewriteEngine on
rewritecond %{http_host} ^website.com [nc]
rewriterule ^(.*)$ http://www.mywebsite.com/$1 [r=301,nc]
RewriteRule ^contact\/?$ contact.php [L]
RewriteRule ^terms\/?$ terms.php [L]
**RewriteRule ^picture/(.*)/$ picture.php?$1 [L]**
Please help,
I have no clue what is the problem.
Try adding
<base href="www.mywebsite.com" />
At the top of your page, this might work.
EDIT:
Try using this rewrite rule
RewriteRule picture/(.*)/$ /picture.php?$1 [L, NC]
assuming that the first part of your htaccess works, replace your last line with the following:
RewriteRule ^picture/(.*)$ /picture.php?$1 [NC]

rewrite subdomain to domain

I have a request that would look something like this http://cariers.example.com/style/all.css that would need to be rewritten to http://www.example.com/style/all.css. The request could be anything from a file like .css or .js to an actual page .aspx.
Thanks for your help
Give this a try (for ISAPI_Rewrite 3):
RewriteBase /
RewriteCond %{HTTP_HOST} ^[^.]+\.example\.com$ [NC]
RewriteRule ^(.*\.(?:css|js|aspx))$ http://www.example.com/$1 [NC,L]

RewriteRule question

Is there any way i can use RewriteRule to show these links:
/articles_history.php
/articles_geography.php
as
/articles/history.html
/articles/geography.html
I created a .htacesss file on my root directory and would like to know if the above is possible by placing some kind of code in the .htaccess file.
RewriteEngine On
RewriteRule /articles/(.+)\.html /articles_$1.php [L,QSA]
Yes it is.
See http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html
In addition to RewriteRule, you also need to usually turn the rewrite engine on by the RewriteEngine directive.
Try this in your .htaccess:
RewriteEngine on
RewriteRule ^article/([^/]+)\.html$ articles_$1.php [L]
And for an arbitrary input:
RewriteEngine on
RewriteRule ^([^/]+)/([^/]+)\.html$ $1_$2.php [L]

Resources