RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^myfile\.php$ redirector\.php?og_path=new_file_1[L,NC,QSA]
RewriteRule ^myfile\.php$ redirector\.php?og_path=new_file_2[L,NC,QSA]
I have my htaccess set up with a simple rewrite rule similar to above. When I go to www.mysite.com/myfile.php the first redirector will be ignored and instead it will automatically go to the second (new_file_2). Every other rewrite rule works as expected.
Curiously though, it works fine on my localhost, but for some reason on my server it give me the error.
Related
I have a URL called
http://localhost:8080/text/index.php?id=2
and I have to redirect on
http://localhost:8080/text/2
So I added the below code in the .htaccess but it's not working
RewriteEngine On
RewriteRule ^([^/d]+)/?$ index.php?id=$1 [QSA]
I refer to the below two links. Is there any issue with my code?
common-htaccess-redirects-19-6-2018 and htaccess-rules
After suggested answer, I tried below code
HTML
Register
login
or
Register
login
.htaccess code
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^[\w-]+/(\d+)/?$ index.php?id=$1 [QSA,L]
With your shown samples, please try following. Please make sure to clear your browser cache before testing your URLs. This considers that you are
hitting URL http://localhost:8080/text/2 in browser.
##Making RewriteEngine ON here.
RewriteEngine ON
##Placing conditions to check if these are non-existing pages only.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
##Writing rule to rewrite to index.php with needed variable here.
RewriteRule ^[\w-]+/(\d+)/?$ index.php?id=$1 [QSA,L]
Issues in OP's attempt: You are trying to attempt to match digits in starting where your url doesn't have digits, so rather use [\w-]+ with it. Also use QSA,L flags with your rewrite rule to handle query string and come out of the rule in case this is executing.
I have been searching with no success on getting my mod rewrite rule to work. I am creating a site like most now that use a rewrite rule to point back to a specific php file that will display content based on the url. The issue i am having, is trying to get the rewrite rule NOT to apply if the user went to "something.com/phpmyadmin" I know it has been asked before, and i have read those posts, but i still cant seem to get mine to work, here is the rewrite scripts i have, and it is still sending me to the /index.php instead of /phpmyadmin/
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/phpmyadmin
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .* index.php
If i go to /phpmyadmin/index.php it works fine, but i am really bothered why i cant get the directory part to work.
You should use THE_REQUEST variable:
RewriteEngine on
RewriteCond %{THE_REQUEST} !/phpmyadmin [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
THE_REQUEST variable represents original request received by Apache from your browser and it doesn't get overwritten after execution of some rewrite rules.
I'm trying to use an htaccess file with 2 rules. The first one is working, but the second displays a white page with the URL in browser correct. If I delete first, rule the second one works. I don't know how to make it work with more than one rule.
RewriteEngine On
RewriteCond %(REQUEST_FILENAME) !-f
RewriteCond %(REQUEST_FILENAME) !-d
RewriteRule ^([a-z0-9]+)$ /profile.php?username=$1
RewriteRule ^([a-z0-9]+)$ /display.php?fly_id=$1
I'm using the following RewriteRule in my .htaccess, which is working fine.
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
However, there is one thing that is troubling me:
I have a subfolder called "folder"
I request the URL http://www.example.com/folder
The URL changes to http://www.example.com/folder/?q=folder
Any other URL works as expected, including http:// www.example.com/folder/
It doesn't make a difference as far as the GET variable is concerned, of course.
But it would be nicer if the argument would not become visible in the browser. I tried adding a slash before index.php, but that resulted in an Internal Server Error.
Any help would be appreciated!
Add this before your RewriteRule:
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
I’m trying to use the following .htaccess file
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^images/
RewriteRule (.*) view.php?picid=$1 [L]
RewriteRule ^/user/(.*)$ /users.php?user=$1
I want two things to happen: Whenever someone requests /1234, it redirects to /view.php?picid=1234, and also when someone visits /users/bob, it redirects to /users.php?user=bob.
My code however, doesn’t seem to be working correctly.
There are several ways to do that. Here’s one that should work:
RewriteRule ^user/(.+)$ users.php?user=$1 [L]
RewriteRule ^([0-9]+)$ view.php?picid=$1 [L]
The first rule will catch any request that’s URI path begins with /user/ followed by one or more arbitrary characters. And the second will catch any request that’s URI path begins with / followed by one or more digits.
The initial problem with your rules is that the RewriteRule with (.*) will match everything.
If you do not want it to match a URL with a slash in it (such as users/bob), try ^([^/]*)$
Secondly, after a URL is rewritten, the new URL goes through your rules again. If you want to avoid matching something that has already been rewritten once, you should add a condition like
RewriteCond %{REQUEST_URI} !\.php