Guys can you help me I want to clean up my url using htaccess.
http://localhost/website/index.php?page=directory&id=1
http://localhost/website/directory/1
Use below rule in your website directory,
RewriteEngine On
# neither a directory nor a file
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([\w-]+)/([\w-]+)$ index.php?page=$1&id=$2 [QSA,L]
index.php
click
submit.php
<?php
echo $_GET['id'];
echo $_GET['page'];
?>
.htaccess
RewriteEngine on
RewriteRule ^([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/?$ submit.php?page=$1&id=$2 [NC,L]
Related
I had added this code in .htaccess for removing .php extension from the url's.Also I had written a code for making blog url seofriendly like https://url.com/posttitle
<IfModule mod_rewrite.c>
#removing extension from url
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
#blog
#if the file with the specified name in the browser doesn’t exist, or the directory in the browser doesn’t exist then procede to the rewrite rule below
RewriteCond %{REQUEST_FILENAME} !-d [NC]
RewriteCond %{REQUEST_FILENAME} !-f [NC]
RewriteRule ^(.*)$ blog_detail.php?id=$1 [QSA,L]
</IfModule>
I had added links like Home.
Home
How to remove index from url in this case?
You can simply use a "/" in your href attribute when navigating to your root (index.html/.php)
I have a static html website and I am using the following code to remove the .html extension for SEO reasons:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^.]+)$ $1.html [NC,L]
Problem is when I add a subdirectory /blog/ I get a 403 Forbidden error. Any help please?
Try this, you were missing the html condition.
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html
I am building my own PHP MVC framework from scratch on ubuntu. .htaccess file is not properly working in it. The folder structure and the .htaccess file content are as bellow.
Folder Structure
/MyMVCProject
/controllers
index.php
help.php
/libs
/modles
/views
.htaccess
index.php
.htaccess File content
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
When I type localh0st/MyMVCProject/help it gives me the following error.
Not Found
The requested URL /MyMVCProject/help was not found on this server.
Apache/2.2.22 (Ubuntu) Server at localh0st Port 80
And I'm sure I have enabled mod_rewrite.
Try to do it this way and from $_REQUEST array you can get url parameter and handle it in your index.php file.
Also for testing purpose add
echo <pre>;
print_r($_REQUEST);
echo </pre>;
at first lines of index.php
<ifModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/$ [NC]
RewriteRule ^(.*)$ /$1 [R=301,L]
</ifModule>
Try following RewriteRule (Copied and bit modified from Zend framework)
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^(.*)$ index.php?url=$1 [QSA,NC,L]
I encountered the same thing, in my case the error was produced when I had a help.php file in the same directory. Don't know exactly why this happens...
You need to add:
RewriteBase /MyMVCProject
to your .htaccess file.
I have a URL like this: http://www.domain.com/index.php?token=123
I want to rewrite the url to this: http://www.domain.com/123 or http://www.domain.com/123/
With this htaccess i can access http://www.domain.com/123/ but my css is then not loaded.
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [L]
RewriteRule ^([^/]+)/$ index.php?token=$1 [L]
Regards
If I guess right than is your problem that you link relativ to your css file. So you need to correct the path to your css file.
I am required to remove .php extension and query string as well from url by rewriting the url
I know this can be done in .htaccess file
I have this in my .htaccess file so far
RewriteEngine on
DirectoryIndex Home.html
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteCond %{REQUEST_URI} !/$
RewriteRule (.*) $1\.php [L]
# if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# otherwise forward it to index.html
RewriteRule .* Home.html
now the url
example.com/blog.php?post=12&comment=3
can be accessed by
example.com/blog.php/post/12/comment/3
but i want to remove .php extension as well
this must be accessible through this url
example.com/blog/post/13/comment/3
Any help?
Thank you in advance.
Searches for everything except . after /
RewriteRule ^(([^/]+/)*[^.]+)$ /$1.php [L]