why is this mod_rewrite rule not working? - mod-rewrite

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]

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]

How to rewrite url to omit one parameter

I have the following url. I want to rewrite the following url to omit the "view" from the url.
Here is currently my existing mod rewrite
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?url=$1 [PT,L]
</IfModule>
http://example.com/page/view/helloworld
How do i rewrite the url to make it
http://example.com/page/helloworld
the keyword helloworld is dynamic.
Expert advice appreciated.
You might want to add the R=301 into the flags if you are worried about transfering SEO.
RewriteEngine On
RewriteRule ^(.+)/view/(.+)$ /$1/$2 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?url=$1 [PT,L]

Mod_Rewrite Exclude a url (URI Exception)

I am using this mod-rewrite rule to redirect the just the homepage of my site to the /it/ sub-directory on the same site.
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
RedirectMatch 301 ^/$ http://www.example.com/it/
However, I want to exempt this url from being redirected
http://www.example.com/?act=25
How can I write an exempt condition to do this?
Found a solution
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
RewriteCond %{QUERY_STRING} !^act=(.*)$ [NC]
RewriteRule ^$ http://www.example.com/it/
Oh, and RewriteCond does not work with RedirectMatch in case you didn't know (I didn't and wasted hrs because of it)

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]

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