Mod Rewrite rules for a subdirectory - mod-rewrite

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]

Related

how to remove further url link from codeigniter?

I have creating a website using codeigniter framework which having following link like (xyz.in/index.php/abc) but I want to open my index page using only xyz.in. how can I do this? Please help me.
Thank You
have you tried with .htaccess file
RewriteEngine On
RewriteBase /root_folder_name/
RewriteCond %{REQUEST_URI} ^system.*
RewriteCond $1 !^(index\.php|images|js|uploads|css|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
more info -> CodeIgniter removing index.php from url
RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
Make .htaccess file put this code in it and place the file outside your Application folder.

.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]

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]

Rewrite ignoring files in a directory when it exists

I have been using successfully the following rewrite that takes www.site.com/123/abc to points it to www.site.com/index.php?id=123&page=abc
RewriteEngine On
RewriteRule ^([0-9]+)$ http://%{HTTP_HOST}/$1/ [R,L]
RewriteRule ^([0-9]+)/(.*)$ /index.php?id=$1&page=$2 [L]
Until now. When a directory that exists and matches the $1 www.site.com/123/ the files in the /123/ directory I no have access to. If I try changing the rewrite to the following everything stills works except the files.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([0-9]+)$ http://%{HTTP_HOST}/$1/ [R,L]
RewriteRule ^([0-9]+)/(.*)$ /index.php?id=$1&page=$2 [L]
What would one use to keep using mod rewrite and not ignore files in a directory when it exists.
RewriteConds only apply to the very next RewriteRule. Since you have two rules you need to repeat your conditions.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([0-9]+)$ http://%{HTTP_HOST}/$1/ [R,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([0-9]+)/(.*)$ /index.php?id=$1&page=$2 [L]
Or you could filter out files and directories at the top before continuing with your rewrite rules:
# Do nothing if URL points to existing file or directory.
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule (.*) $1 [L]
RewriteRule ^([0-9]+)$ http://%{HTTP_HOST}/$1/ [R,L]
RewriteRule ^([0-9]+)/(.*)$ /index.php?id=$1&page=$2 [L]

A little help on a mod_rewrite expression

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.

Resources