A little help on a mod_rewrite expression - mod-rewrite

I need a very quick fix in a mod_rewrite expression for drupal we have
RewriteCond %{REQUEST_URI} !(\.gif)|(\.jpg)|(\.png)|(\.css)|(\.js)|(\.php)$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
But i need to redirect the value of the subdomain in get too so i need something that will give:
RewriteCond %{REQUEST_URI} !(\.gif)|(\.jpg)|(\.png)|(\.css)|(\.js)|(\.php)$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteRule ^(.*)$ index.php?subdomain=THE SUBDOMAIN HERE&q=$1 [L,QSA]
Don't know how to do it, please help!

Trying this again, for some reason my code isn't rendering properly.
RewriteCond %{REQUEST_URI} !(\.gif)|(\.jpg)|(\.png)|(\.css)|(\.js)|(\.php)$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteCond %{HTTP_HOST} ^(.*)\.mydomain\.com$
RewriteRule ^(.*) index.php?subdomain=%1&q=1 [L,QSA]
Based off of some forum posts I found here.

You don't really need the subdomain in the query string.
The subdomain can be found in PHP in $_SERVER['SERVER_NAME'].
PHP documentation says:
'SERVER_NAME'
The name of the server host under which the
current script is executing. If the script
is running on a virtual host, this will be
the value defined for that virtual host.

Related

.html is not getting appended in the URL in new AEM set-up

We are setting up AEM for the first time and we are facing the issue that the URLs fail to have .html in it. from example if the URL should be
http://dev.alfaromeousa.com/cars/usa/en.html
it actually coming as
http://dev.alfaromeousa.com/cars/usa/en/
For temporary solution we added the below rewrite rule
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} \.(gif|jpe?g|png|js|css|swf|php|ico|txt|pdf|xml)$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ - [L]
RewriteCond %{REQUEST_URI} !^.*.html$
RewriteRule ^(.*)$ $1.html [L,R=301] 
But it fails when the URL are like
http://dev.abc.com/cars/usa/
by adding an .html. So URL turns into
http://dev.abc.com/cars/usa/.html.
Can anyone please help me with figuring out if i missed out something in set-up or did anything wrong
The issue was resolved with the below rewite rule :
RewriteCond %{REQUEST_URI} !^/aemusaerror/(.*) [NC]
RewriteCond %{REQUEST_URI} !^/content/dam(.*) [NC]
RewriteCond %{REQUEST_URI} !^/etc/designs(.*) [NC]
RewriteCond %{REQUEST_URI} !^/vl/(.*)json [NC]
RewriteCond %{REQUEST_URI} !^/timestamp [NC]
RewriteCond %{REQUEST_URI} !(.*)\.[a-zA-Z0-9-]+$
RewriteCond %{REQUEST_URI} !^/renderer/(.*) [NC]
RewriteRule ^(/.*)$ /content/alfausa/en$1.html [P,L]

why is this mod_rewrite rule not working?

I have this rule:
RewriteEngine On
RewriteRule ^([^/]*)$ /?id=$1 [L]
And it's supposed to make http://www.somedomain.com/?id=3123123 accessible as http://www.somedomain.com/3123123 but I then get a 500 error. Why is that?
I ended up using this:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/index.php
RewriteRule ^(.*)$ /index.php?id=$1 [L]

URL Rewriting (Mod_Rewrite)

Hi I know absolutely nothing about mod_rewrite.
I'm asking how I could rewrite this URL as needed.
website.com?page=pagename&content=contents&action=download
as
website.com/pagename/contents/download
the param "action" will not always be set. Unsure if that makes a difference.
Try adding this to the htaccess in your document root:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/?$ /?page=$1&content=$2&action=$3 [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/([^/]+)/?$ /?page=$1&content=$2 [L,QSA]

rewriterules remove .php in the middle of url

I'm having trouble rewriting url from /video.php/test-video to /video/test-video
I currently use:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?/$1 [L]
#RewriteRule ^/video/(.*)$ /video.php?/$1 [L]
I already rewrite index.php/url-with-white-list to /url-with-white-list.
Now I've had a video.php file that uses url from a database.
I just would like to rewrite video.php/url-of-the-video to video/url-of-the-video to
My rewrite of index.php works but I can't make my rewrite of video.php works.
Any ideas ?
By advance, thanks a lot !
Any suggestion ?
Thanks by advance
Solutions :
RewriteCond %{REQUEST_URI} ^(.*)video/(.*)
RewriteRule (.*)video/(.*)$ /video.php?/$2 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?/$1 [L]

Mod Rewrite rules for a subdirectory

I have a drupal installation set up in a subdirectory of a domain (www.mydomain.com/cms), but I'm having trouble getting the queries to format correctly using mod_rewrite. I need url requests coming in as:
{domain}/cms/admin/content/node
to be interpreted as:
{domain}/cms/?q=admin/content/node
Here's what I have:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteCond %{REQUEST_URI} ^/(cms/.*)$
RewriteRule ^(.*)$ cms/?q=$1 [L,QSA]
Any pointers on where I'm going wrong?
Where these rules you posted are located? If you create a .htaccess inside the "cms" directory with the following content, I believe it should work fine:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]

Resources