rewrite subdomain to domain - isapi-rewrite

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]

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]

mod_rewrite forward shortend URL

I am looking for a way to create a short URL path for a longer URL on my page
the long url is: domain.com/tagcloud/user.html?t=1234ABCD
i would like to offer a short version of the URL to easy access it:
domain.com/t/1234ABCD
I tried a few examples but I just don't get it how I could forward these rules.
RewriteRule ^(.*)/t/$ /tagcloud/user.html?t=$1 [L]
I am also using MODX so they already use rules.
in addition my htaccess file
RewriteEngine On
RewriteBase /
# Always use www
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^www\.domain\.com [NC]
RewriteRule (.*) http://www.domain.com/$1 [R=301,L]
# The Friendly URLs part
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
I must keep the code snippets above in my htaccess file. The first one simply forwards http://domain.com requests to www.domain.com
The friendly URLs part is needed to translate the internal IDs of my CMS with the alias of the URL. This feature must remain because the entire site cannot be influencted by the changes I try to make in htaccess...
I simply would like to add a listener that only if the URL matches www.domain.com/t/abcd1234
Therefore I need something that identifies the www.domain.com/t/ URL
your help is much appreciated
Try this:
RewriteCond %{REQUEST_URI} ^/t/.*
RewriteRule ^t/(.*)$ /tagcloud/user.html?t=$1 [R=301,L]

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

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]

How can I use mod_rewrite to do this

I would like to take a url at my site:
http://mysite.com/jk/drawing
but operationally drop the "jk" dir and have my users see this:
http://mysite.com/drawing
Is this possible? If so can someone give me an example of how it is done?
thanks,
The first thing you need to do is go and change all of your links from looking like this: http://mysite.com/jk/drawing to looking like this: http://mysite.com/drawing. Without doing this, people will still see all the /jk/ URLs everywhere, the only thing you can do about it is to make sure you've changed all your links. Then add these rules to the htaccess file in your document root:
RewriteEngine On
RewriteCond %{HTTP_HOST} mysite.com [NC]
RewriteCond %{REQUEST_URI} !^/jk/
RewriteRule ^(.*)$ /jk/$1 [L]
In order to correct for all the links still pointing to /jk/ that you don't have any control over:
RewriteCond %{HTTP_HOST} mysite.com [NC]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /jk/([^\ ]*)
RewriteRule ^ /%1 [R=301,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]

Resources