how do I rewrite this url with .htaccess mod_rewrite
http://55.100.10.66:81/var/class/tag?isAjax=true&id=189&key=eJwVxzEOwjAMB&callback=_prototypeJSONPCallback_0
to
http://55.100.10.66:81/index.php/var/class/tag?isAjax=true&id=189&key=eJwVxzEOwjAMB&callback=_prototypeJSONPCallback_0
Amongst a lot of things I tried the below which doesn't work
RewriteRule ^var/class/tag(.*) /index.php/var/class/tag$1 [L,NC,QSA]
Thanks!
This is the solution
RewriteCond %{REQUEST_URI} ^/var/class/tag(.*)
RewriteRule .* index.php [L]
You cannot match QUERY_STRING from RewriteRule. Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteRule ^(var/class/tag/?)$ /index.php/$1 [L,NC]
Related
I am 301 redirecting everything from http://something.org/* to https://something.com/* with this code...
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine on
RewriteRule (.*) https://www.something.com/$1 [R=301,L]
</IfModule>
I am trying to add exception that this URL http://something.org/registration/service redirects to http://www.something.com/registration/service (not HTTPS like general rule). Tried this to exclude this url from general rule and it works, but I don't know how to add rule to redirect this exclusion to something else:
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/registration/service
RewriteRule (.*) https://www.dewesoft.com/$1 [R=301,L]
</IfModule>
Replace your RewriteCond with this :
RewriteRule ^registration/service http://example.com%{REQUEST_URI} [NE,L,R]
I have site e.g. 123.123.123.123/subdirectory/ and I would like to rewrite
123.123.123.123/subdirectory/page/123
to
123.123.123.123/subdirectory/page.php?id=123.
I've created .htaccess file:
RewriteEngine On
RewriteBase /subdirectory
RewriteRule ^page/(.*)$ page.php?id=$1 [NC,L,QSA]
but it doesn't work (rewriting in on).
Use this rule and it will work.
RewriteRule ^123\.123\.123\.123/subdirectory/page/123$ /123.123.123.123/subdirectory/page.php?id=123&%{QUERY_STRING}
I have problem with .htaccess.
I need:
if $_SERVER["HTTP_HOST"] is sub.site.com must show content from www.site.com/sub/. But URL must be like sub.site.com.
And if sub.site.com/content/ must show content from www.site.com/sub/content/
Is it Possible?
Setting subdomains from hosting not working for me because of my CMS.
Try adding these rules to the htaccess file in your document root:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^sub.site.com$ [NC]
RewriteCond %{DOCUMENT_ROOT}/sub%{REQUEST_URI} -f [OR]
RewriteCond %{DOCUMENT_ROOT}/sub%{REQUEST_URI} -d
RewriteRule ^(.*)$ /sub/$1 [L]
Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^sub\.site\.com$ [NC]
RewriteRule (?!^sub/)^(.*)$ /sub/$1 [L,NC]
I have a htaccess question that I think may be so simple (dumb?) that no one has had to ask it before. I converted from using html pages to php and for the most part the following has worked:
<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine on
RewriteRule ^(.+)\.htm$ /htmlrewrite.php?page=$1 [R=301,NC,L]
</IfModule>
There are a couple of exceptions though so I assumed putting:
Redirect 301 /oldpage.htm http://example.com/newpage.php
above the IfMofule... would do the trick but it doesn't. The "Redirect 301" is being ignored unless I remove the rest of the code. Could someone tell me what I'm doing wrong?
TIA.
You're using mod_rewrite and mod_alias together and they are both getting applied to the same URL. You should stick with either mod_rewrite or mod_alias.
mod_rewrite: (remove the Redirect directive)
<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine on
RewriteRule ^oldpage.htm$ http://example.com/newpage.php [R=301,L]
RewriteRule ^(.+)\.htm$ /htmlrewrite.php?page=$1 [R=301,NC,L]
</IfModule>
mod_alias: (remove everything in the <IfModule mod_rewrite.c> block:
Options +FollowSymlinks
Redirect 301 /oldpage.htm http://example.com/newpage.php
RedirectMatch 301 ^/(.+)\.htm$ /htmlrewrite.php?page=$1
Apache processes mod_rewrite (Rewrite*) first and then mod_alias (Redirect).
Use RewriteCond to prevent /oldpage.htm from processed by mod_rewrite.
RewriteCond %{REQUEST_URI} !^/oldpage\.htm$
RewriteRule ^(.+).htm$ /htmlrewrite.php?page=$1 [R=301,NC,L]
Or use RewriteRule instead of Redirect.
RewriteRule ^oldpage\.htm$ http://example.com/newpage.php [L,R=301]
RewriteRule ^(.+).htm$ /htmlrewrite.php?page=$1 [R=301,NC,L]
My folder for public_html is /domain.com/public_html/ but i want the htaccess to redirect them to the folder /domain/public_html/www/ but still have domain.com as domain and not domain.com/www .
EDIT:
I want the subfolder www in the public_html do be the default root and not public_html itself
Any solution on this?
Here is my current htacess
Options +FollowSymlinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.*)$ www/$1 [NC,L]
</IfModule>
If you can only go for .htaccess, this simple one should do it;
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/www/
RewriteRule ^(.*)$ /www/$1 [QSA]
Explanation;
RewriteEngine on # Turn on mod_rewrite functionality
RewriteCond %{REQUEST_URI} !^/www/ # Don't rewrite requests that are
# already to the /www/ directory.
# If this isn't here, we'll go into
# a neverending loop.
RewriteRule ^(.*)$ /www/$1 [QSA] # Rewrite all else to the www subdirectory
# QSA = keep the query string.
EDIT: Didn't see your existing htaccess, this (minus the redundant RewriteEngine statement) should probably go at the end instead of the whole IfModule block.
Try to put this in the htaccess on the public_html folder:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.*)$ www/$1 [NC,L]
</IfModule>
OR
Edit the apache configuration (httpd.conf)
vi /usr/local/apache/conf/httpd.conf
and set the DocumentRoot of the domain as
DocumentRoot /home/user/public_html/www
Save the file and restart the httpd service.
OR (recomanded)
Take a look at this question(and it's answer) - https://stackoverflow.com/a/5891858/1361042
EDIT
Use this HTACCESS:
<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/www/
RewriteRule ^(.*)$ www/$1 [NC, QSA]
</IfModule>
don't add it to yours but replace your htaccess with this one.