I have downloaded a web template and when i try to run that in my localhost the folder doesn't show up.that folder contains a .htaccess file.When i remove that file i can see the folder but when i open that it gives some errors.
This is the .htaccess file
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^$ index.php [L]
RewriteRule ^([a-zA-Z0-9]+)?$ user-profile.php?user_username=$1 [NC,L]
this is the first time i'm working with a .htaccess file...
Any help is appreciated.
Maybe problem in the index.php file PHP code? Rewrite rules looks fine.
Show us the Apache error log and a rewrite log, without that hard to say what is wrong.
It looks like the RewriteCond directive is in the wrong place...? I would have thought it should apply to the 2nd RewriteRule, not the first:
RewriteEngine On
RewriteRule ^$ index.php [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([a-zA-Z0-9]+)?$ user-profile.php?user_username=$1 [NC,L]
RewriteCond directives apply to the single RewriteRule that follows. That 2nd ruleset basically says that if the requested file does not exist then internally rewrite the request to the user-profile.php page passing the request (which is assumed to be a username) to the user_username parameter.
Related
So I have included an htaccess file to my server in the root directory and changed all of the ./ I could find set the absolutes.
However, when I search by URL into one of the directories pressing the home button does not take me home. Instead, it appends the index onto the end:
/website/book/index.php?p=home
Instead of
/website/index.php?p=home
Where have I made a fuddle?
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+[^/])/$ https://%{HTTP_HOST}/paperbound/$1 [R=301,L]
RewriteRule ^([^/\.]+)?$ index.php?p=$1 [L]
RewriteRule ^([^/\.]+)/([^/\.]+)$ index.php?p=$1&id=$2 [NC,L]
</IfModule>
Is the htaccess used. https://sitehost/website/book/2 is URL entered and page retrieved which exists as https://sitehost/website/index.php?p=book&id=2, clicking navlink to return to https://sitehost/website/index.php?p=home, instead places https://sitehost/website/book/index.php?p=home into the URL bar and returns an error as the file does not exist.
With your shown samples/attempts, please try following htaccess rules file. Make sure to keep your index.php file is present in website folder and htaccess is present along side with website folder(not inside it).
Please make sure to clear your browser cache before testing your URLs.
##Enabling rewrite engine here.
RewriteEngine ON
##Checking conditions for non-existing pages here.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
##performing internal rewrite here to index.php file.
RewriteRule ^([^/]*)/([^/]*)/([^/]*)/?$ $1/index.php?p=$2&id=$3 [QSA,L]
I am getting started with the mod_rewrite function for my PHP webpage
I was superexcited to have created my first rewrite rule, but when I added to my .htaccess file, I got error 500 for all webpages (not only the one I am trying to redirect).
Here is my file:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^([^/]*)/(([^/]*)/)*$
RewriteCond %{REQUEST_FILENAME}index.php !-f
RewriteCond %{REQUEST_FILENAME}index.html !-f
RewriteCond %{REQUEST_FILENAME}index.htm !-f
RewriteRule ^/([a-zA-Z\-]+)\/([a-zA-Z\-]+)\/([0-9]+)$ ficha_jugador.php?idjugador=$3 [L]
RewriteRule (.*) /index.html [L]
My new line is 8th, the rest came by default in my webserver
I tried something much easier for line 8th just to test
RewriteRule ^writetest\.html http://www.after5pc.net [QSA,L]
But it also ended up in 500 error, so it does not seem a syntax problem
Eventually, what I want to do is to change (slug my URLs)
http://cadistas1910.com/ficha_jugador.php?idjugador=1304
by
http://cadistas1910.com/alvaro-garcia-canto/alvaro-garcia/1304
Any help you guys can provide? Thanks a lot!
I believe last line of your .htaccess file could be the culprit, could you please try following once.
RewriteEngine On
RewriteBase /
RewriteRule ^([a-zA-Z\-]+)\/([a-zA-Z\-]+)\/([0-9]+)$ ficha_jugador.php?idjugador=$3 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.html [L]
I have added a condition there to rewrite to index.html if and only if Uri has non existing directory/file, why because it will create an infinite loop without a condition, since you are rewriting everything to index.html and everything(by regex) matched index.html also, hence loop and 500 internal error you are getting.
Also your rule to rewrite from http://localhost:80/alvaro-garcia-canto/alvaro-garcia/1304 TO http://localhost:80/ficha_jugador.php?idjugador=1304 have been changed into a single line above.
NOTE: To fix this either make your links absolute or use base tag. In the header of your webpage add this <base href="/"> so that your relative links can load from the correct location.
Does anyone know how to change the URL for all php files inside a subfolder of the root directory and also remove .php?
http://localhost/pages/x.php
to
http://localhost/x
Example:
http://localhost/pages/example.php
to
http://localhost/example
You can do it like this, which only executes if the request exists in pages and doesn't exist in root. So existing items in root don't get rewritten.
RewriteEngine on
RewriteCond %{CONTEXT_DOCUMENT_ROOT}/$1 !-f
RewriteCond %{CONTEXT_DOCUMENT_ROOT}/pages/$1.php -f
RewriteRule ^([^/]+)$ pages/$1.php
RewriteEngine On
RewriteRule ^x$ page/x.php [L]
RewriteRule ^example$ pages/example.php [L]
I'm trying to write an htaccess file and I'm having trouble getting it to work properly. There's a directory on my site called 'gpio'. The htaccess file that I'm writing is in /var/www/gpio.
When someone requests the URL http://domain.com/gpio, I want the request to be redirected to a script, with 'gpio' appended to the query string. This is what I've got in my htaccess file:
# .htaccess
#DirectoryIndex index.html
RewriteEngine on
# I changed domain name a few months ago...
RewriteCond %{HTTP_HOST} ^olddomain.com/*$
RewriteRule ^(.*)$ http://newdomain.com/$1 [R=301,L]
# handle the case where the directory exists
RewriteCond %{REQUEST_FILENAME} -d
# this is the part that doesn't work
RewriteRule ^(.*)$ /cgi-bin/pyindex.cgi?q=$1 [L,QSA]
# handle the case where a file is requested
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /cgi-bin/pyindex.cgi?q=$1 [L,QSA]
The problem is that when I visit this URL, I get redirected to the script, but the requested path doesn't get appended to the query string. In pyindex.cgi, when the query string is printed, it just contains 'q='. The end result is that I'm seeing my home page when I should be seeing a page representing a category of posts.
Any thoughts on what I'm doing wrong would be appreciated.
Either have that rule inside /var/www/.htaccess or modify it as
RewriteRule ^$ /cgi-bin/pyindex.cgi?q=gpio [L,QSA]
RewriteRule ^(.+)/?$ /cgi-bin/pyindex.cgi?q=gpio/$1 [L,QSA]
And, the following rule tests if the request is not a file (and hence would match directories as well)
RewriteCond %{REQUEST_FILENAME} !-f # remove ! to match files
I know there are lots of question on htaccess, yet I tried the different code I could find on Google and StackOverFlow, none worked.
I have the following in my root :
index.php
.htaccess (the one I am trying to write)
controllers
--index.php
--mycontroller.php
models
--mymodel.php
view
-index.php
--myview.php
(I am working on localhost with MAMP&Firefox)
What I have is this link
localhost:8888/MySite/controllers/mycontroller.php
What I want is
localhost:8888/MySite/mycontroller
And when I manually enter the url, I would like it to be redirected to the right controller in my MVC code
I tried this :
RewriteEngine On
RewriteBase /
RewriteRule ^/(.*)$ /controllers/$1 [L]
It doesn't redirect when I go to blabla/controllers/mycontroller.php and doesn't understand what I am asking when I manual go to blabla/mycontroller.
If your base is in /MySite/ then it needs to reflect the RewriteBase:
RewriteEngine On
RewriteBase /MySite/
# match against the php filename
RewriteCond %{REQUEST_URI} ^/Mysite/(.*)$
# check to see if the request, routed through controllers actually points to an existing file
RewriteCond %{DOCUMENT_ROOT}/MySite/controllers/%1.php -f
# rewrite
RewriteRule ^(.*)$ controllers/$1.php [L]
This should take a request for the URI: /MySite/foo and rewrite it to /MySite/controllers/foo.php if there's a foo.php file in the controllers directory.
Did this to make it work :
RewriteEngine On
RewriteBase /MySite/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ controllers/$0.php [L]