I'm trying to build a shopping cart using PHP & MySQL. Right now I'm in the process of creating product-detail pages. So this is how I set up my htaccess (located in the root folder):
Options +FollowSymLinks
Options -Indexes
DirectoryIndex index.php
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond $1 !^(index\.php|resources|images|css|js|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^\.]+)$ $1.php [NC,L]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 /index.php
</IfModule>
My problem is I can only access a certain page if index.php is included. For example, http://localhost/thegamingplace/products/details/1 displays a "Not Found" error, but http://localhost/thegamingplace/index.php/products/details/1 works.
Can someone take a look at my htaccess and tell me what I'm doing wrong?
Try this:
RewriteCond %{REQUEST_URI} !^(index\.php|resources|images|css|js|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^\.]+)$ index.php/$1 [NC,L]
It works when tested at http://htaccess.mwl.be/
If it doesn't work make sure you have mod_rewrite installed and enabled.
Related
I have a static website running in conjunction with wordpress in the same dir, it all works fine. However, on the static pages that don't use wordpress I cannot seem to remove the .php file extensions my .htaccess file looks like this:
# BEGIN WordPress
<IfModule mod_rewrite.c>
ErrorDocument 404 /index2.php
RewriteEngine On
RewriteBase /index.php/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
#Alternate default index page
DirectoryIndex index2.php
ErrorDocument 404 http://example.com/index2.php
I have tried adding this code as you usually would but it wont work:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
Try this
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php [L]
Hi I have the following redirection for a friendly URL site
Options +FollowSymLinks -Multiviews
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
rewritecond %{SCRIPT_FILENAME} !-d
rewritecond %{SCRIPT_FILENAME} !-f
rewriterule ^(.*)$ $1.php [L]
rewriterule ^noticia/([a-zA-Z0-9_-]+)$ noticia.php?title=$1 [L]
</IfModule>
If i go to www.mysite.com/noticias or any other URL like that everything goes ok
But if i try to go to www.mysite.com/noticia/this-is-a-parameter
When I access a link I do it like <a href="noticia/this-is-a-parameter">
I get Internal Server Error message and white screen
In localhost it was working perfectly, but can't find a solution in the server.
Any help would be appreciated
Check for presence of .php file before adding php extension and reorder your rules:
Options +FollowSymLinks -Multiviews
RewriteEngine on
RewriteBase /
RewriteRule ^noticia/([\w-]+)/?$ noticia.php?title=$1 [L,QSA,NC]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+?)/?$ $1.php [L]
Rewrite rule does not work on remote host in subdirectory.
While in production phase, I had this directory http://localhost/prj/. I used RewriteRule to "hide" and "load" PHP files without extension. This is the .htaccess I've used:
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
So, that worked fine, I've developed the project and I wanted to upload it to my VPS for remote use and such. The thing is, the project is still in beta, and I don't keep it in root directory ATM but at subdirectory /beta/, so now, this my URL right now is like this: http://example.com/beta/.
Yet when I tried to access that URL, the index.php is automatically loaded, but when I access for example file play.php as http://example.com/beta/play it doesn't work but it worked while the project was in production.
This is what I have tried:
To use RewriteBase to /beta/
RewriteBase /beta/
To use different options
Options All -Indexes -MultiViews
To use directory before actual RewriteRule
RewriteRule ^/beta/(.*)$ $1.php
To use operatives [L, QSA]
Example:
Options All -Indexes -MultiViews
RewriteEngine on
RewriteBase /beta/
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php [L,QSA]
Options All -Indexes -MultiViews
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^/beta/(.*)$ $1.php [L,QSA]
Returned error is 404 Not found.
Edit: I'm I supposed to have too inside apache2.conf?
Try this in /beta/.htaccess:
Options All -Indexes -MultiViews
RewriteEngine on
RewriteBase /beta/
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/beta/$1\.php -f [NC]
RewriteRule ^(.+?)/?$ $1.php [L]
I am currently using a custom MVC Architecture to create my website.
The problem is that when I enter localhost/website/ which in the future would be www.website.com/, I want my homepage to be shown. Currently I am making this work by using localhost/website/home/ but I don't want that, I just want localhost/website/ which automatically shows the homepage.
I have tried to do this with htaccess, but without any success. When I navigate to localhost/website/ it shows me an error 'This webpage is not available'.
My htaccess code: This is found inside my public folder.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?url=$1 [PT,L]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 index.php
</IfModule>
I hope that made some sense and that someone could help me.
Thanks
You can have a new rule like this:
<IfModule mod_rewrite.c>
RewriteEngine On
# handle home page
RewriteRule ^/?$ home [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ index.php?url=$1 [QSA,L]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 index.php
</IfModule>
Try adding, right after the line: RewriteEngine On this rule:
RewriteRule ^$ index.php?url=home [L]
I am new to htaccess file and have the following requirement.
I have a dynamic page which handles like this
com/index.php?postname=products
.com/index.php?cat=news&country=india
for these pages I want SEO friendly urls like this
.com/products/ to .com/index.php?postname=products
.com/news/country to .com/index.php?cat=news&country=india
What code do I need to put it in htaccess file?
Do I need to write RewriteCond or RewriteRule or both?
If possible please give me the sample code to do this.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/?$ /index.php?postname=$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/([^/]+)/?$ /index.php?cat=$1&country=$2 [L]
Try this Example for your work.
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{QUERY_STRING} ^postname=(.*)$
RewriteRule ^index\.php$ /postname/%1? [R=301]
RewriteRule ^postname/([^-]+)$ /postname.php?id=$1 [L]
The above code will redirect
index.php?postname=products
to
index/products
Here is the htaccess code that helps you
Save the line .htaccess in your index.php folder or root folder.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^([A-Za-z0-9_\-]+)$ index.php?postname=$1 [L]
RewriteRule ^([A-Za-z0-9_\-]+)/([A-Za-z0-9_\-]+)$ index.php?cat=$1&country=$2 [L]
</IfModule>
<IfModule mod_security.c>
SecFilterEngine Off
SecFilterScanPOST Off
</IfModule>
<IfModule mod_gzip.c>
mod_gzip_on No
</IfModule>
It works fine for me.