Need help in URL rewrite rules - .htaccess

The URL rewrite condition is always taking me to the index file, i dont know why, below is my case.
my link is:
http://www.anabrokers.com/contents_12/Selling%20Your%20Business
my htaccsess contains the following:
RewriteEngine On
RewriteCond %{REQUEST_URI} contents_
RewriteRule ^(.*)$ /Home/contents.php/?$ [NC,L]
Tips:
Hosted on Godaddy
PHP version 5.3.24

Related

PHP Dynamic URL Parameters and GET

I'd like to ask if it's possible to use a dynamic url and GET at the same time.
Let's say my current dynamic url is: https://yourdomain.com/blog/this-is-a-title
Would it be possible to make this work too: https://yourdomain.com/blog/this-is-a-title?action=delete
RewriteEngine on
RewriteRule ^([0-9]+)$ index.php?id=$1
The dynamic url mentioned first works fine, but I want to make the second work as well.
This is my .htaccess - hope it helps.
PS: I know that the regex in my htaccess isn't correct, it's just an example.
Have your .htaccess Rules file in following manner. Please make sure that your htaccess Rules file is present in root folder(where blog and htaccess both are residing in it; htaccess shiouldn't be inside blog folder; should be place same folder with it). Make sure to clear your browser cache before testing your URLs.
RewriteEngine ON
##Newly added rules here...
RewriteBase /blog/
RewriteCond %{THE_REQUEST} \s/blog/(?:[^?]*)?action=(\S+)\s [NC]
RewriteRule ^ index.php?action=%1 [L]
##Old Rules OP's htaccess ones.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([0-9]+)$ index.php?id=$1

Simple URL rewrite does not work

First, I know there are several questions of this, but what I experience is that other rules work, like removing the .php extension while this rule does not work:
RewriteRule ^hello$ marketplace [NC,R=301]
This is just a simple test, and it's not working. The URL is still marketplace and not hello. And I have tried to remove all other rules I have and let the rule above be the only existing in my htaccess file, but still, not working.
Any ideas? mod_rewrite is clearly turned on because other rules work.
Tested and not working:
RewriteRule ^marketplace$ /hello [NC,R=301]
Highly recommend you to give a read on this "Apache mod_rewrite Introduction"
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+(.*)\.php [NC]
RewriteRule ^ /%1 [R=301,QSA,L]
# Redirect to hello
RewriteRule ^marketplace$ /hello [R=301,NC,L]
# Show the content of marketplace on hello
RewriteRule ^hello$ /marketplace.php [NC,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1\.php -f
RewriteRule ^([^/]+)/?$ $1.php [L]
The above is a fully tested and working rule.
First rule will redirect .php to directory like URL's for example domain.com/marketplace.php becomes domain.com/marketplace.
Second rule redirects marketplace to hello.
Third rule internally redirect hello to marketplace.php so the URL remains hello with the content of marketplace.php.
Last rule will verify it directory does not exist but exist as a php file and internally redirect to it.
So if you access marketplace.php it goes to marketplace then hello and from hello you will see the content of marketplace.php.
If marketplace.php does not exist then you get 404 error.

Liferay: Removing /web/ from all community sites

I can't seem to figure out how to do a url rewrite so that I can remove the /web/ from all of my community sites:
domain.com/web/communitysite1/page
domain.com/web/communitysite2/page
domain.com/web/communitysite3/page
domain.com/web/communitysite4/page
and I want it to be,
domain.com/communitysite1/page
domain.com/communitysite2/page
domain.com/communitysite3/page
domain.com/communitysite4/page
Here's a thread from Liferay, the solution there is using the virtual host; however, that's only for one of the community site for that one domain but I need the domain to be all the same for all the community sites I'm doing.
First, you will have to manualy change your pages links from domain.com/web/community... to domain.com/community
After that you need a rewrite rule to rewrite the new url to the old one without notifying users :
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !^web/
RewriteRule ^(.*)$ /web/$1 [L,QSA]
Then you will need a rule to redirect users that still access the old url to the new one while changing their browser link :
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} ^web/
RewriteRule ^web/(.*)$ /$1 [L,QSA,R=301]
Then you need to mix that up, BUT, if you do, you will get an infinite loop, so you need something to avoid that (a trick I use is to add an optional parameter to the first rule and check in the second one if it exists or not, if it do then you don't redirect) :
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} ^web/
RewriteCond %{QUERY_STRING} !(.*&)?r=0(&.*)?$
RewriteRule ^web/(.*)$ /$1 [L,QSA,R=301]
RewriteCond %{REQUEST_FILENAME} !^web/
RewriteRule ^(.*)$ /web/$1?r=0 [L,QSA]
Thank you #Yazmat for your kind help.
#Prakash K Here's what I am currently using, it's a different solution using proxy mod.
ProxyHTMLExtended On
ProxyHTMLEnable On
SetOutputFilter INFLATE;proxy-html;DEFLATE
ProxyHTMLURLMap ^/web/(.*)$ /$1 Rli

.htaccess rewrite rule not working properly. Redirects to absolute path

I have a .htaccess placed in server.com/site_admin/api (actual directory structure: /public_html/site_admin/api)
I want to direct all requests to the corresponding php file. So api/users would rewrite to api/users.php
So I wrote this rule:
RewriteEngine On
RewriteRule ^(.*)$ $1.php
But it doesn't work. I get a 404 when I access the url server.com/site_admin/users
When I added a [R=301] to it
RewriteRule ^(.*)$ $1.php [R=301]
I found that it redirects to http://server.com/home/server_user/public_html/site_admin/api/users.php
Instead of http://server.com/site_admin/api/users.php
Can someone please help me out here
Use this:
RewriteEngine On
RewriteCond %{REQUEST_URI} !php$
RewriteRule ^(.*)$ $1.php
Yours doesn't work because the rewrited url is still matched by (.*), so it will rewrite it again until cause an error. But it's strange it gives you a 404 instead of 500...
The second one doesn't work because [R] generate a new GET request, so you need to add the host or it will request the absolute path to the defined host and it, obviously, will not work. If you want to use [R], you should use:
RewriteRule ^(.*)$ http://server.com/site_admin/api/$1.php [R]
But it will not solve your problem. As I said, it will generate a new GET request and .php will be visible to your user.

modrewrite - rewrite to new domain from subdirectory

Damn you modrewrite
I have a website hosted at a url like:
http://mydomain/mocks/thesite/
Now I want to move it to a new domain
http://thesitesdomain.com/
My htaccess looks like this:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.thesitesdomain\.com
RewriteRule (.*) http://www.thesitesdomain.com/$1 [R=301,L]
Now this works fine as long as there is something after /mocks/thesite/. eg: http://mydomain/mocks/thesite/index.html redirects to http://www.thesitesdomain.com/index.php.
However the problem is that:
http://mydomain/mocks/thesite/ redirects to http://thesitesdomain.com/mocks/thesite/. Any idea why? How to stop this?
The .htaccess file is in the root of /mocks/thesite/ (if that helps)
Thank you
You should try to use the variable REQUEST_URI you might have a little more success with that. It should be the request uri and file name. To
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.thesitesdomain\.com
RewriteRule .* http://www.thesitesdomain.com/%{REQUEST_URI} [R=301,L]
I can't remember but to also redirect with the query string (get variables) I think you need to add it like this.
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.thesitesdomain\.com
RewriteRule .* http://www.thesitesdomain.com/%{REQUEST_URI}?%{QUERY_STRING} [R=301,L]
Been a while since really doing a domain redirect....
BTW this is a good read on htacces configuration:
http://corz.org/serv/tricks/htaccess2.php

Resources