i need same permalink structure which is in wordpress like that :
http://example.com/wordpress/2015/08/13/sample-post/
I developed blogging in custom php
suppose any blog in year say 2015 month say 08(august) and blog name say apple
then my permalink structure like that :
http://example.com/2015/08/apple/
right now my Url is as below:
http://example.com/view-blog.php?bid=19
where bid means blog id
can anybody help me
Use this code
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
## don't touch /forum URIs
RewriteRule ^forums/ - [L,NC]
## hide .php extension snippet
# To externally redirect /dir/foo.php?bid=123 to /dir/foo
RewriteCond %{THE_REQUEST} ^GET\s([^.]+)\.php\?bid=([^&\s]+) [NC]
RewriteRule ^ %1/%2? [R,L]
# To internally forward /dir/foo/12 to /dir/foo.php?bid=12
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+?)/([^/]+)/?$ $1.php?bid=$2 [L,QSA]
# To externally redirect /dir/foo.php to /dir/foo
RewriteCond %{THE_REQUEST} ^GET\s([^.]+)\.php\s [NC]
RewriteRule ^ %1 [R,L]
# To internally forward /dir/foo to /dir/foo.php
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^(.*?)/?$ $1.php [L]
for more details..read Here
Related
I´m new to .htaccess and I am having problems in rewriting some URLs.
My website is made with php and has 2 parameters: param1 and param2.
The URLs look like similar to:
www.website.com/index.php?param1=12345678
www.website.com/index.php?param1=09876543
www.website.com/index.php?param2=abcdefgh
www.website.com/index.php?param2=qwertzui
I would like to create a .htaccess file to remove “index.php”, replace param1 and param2 with 2 names and add “.html” at the end, so they became:
www.website.com/budget/12345678.html
www.website.com/budget/09876543.html
www.website.com/user/abcdefgh.html
www.website.com/user/qwertzui.html
I have got this code (copied from internet).
It removes the .php extension but in the internally forward it rewrite it at the end of the URL neglecting the parameters.
Is someone so kind to help me to write the code?
Thanks :)
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
## hide .php extension snippet
# To externally redirect /dir/foo.php to /dir/foo
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R,L]
# To internally forward /dir/foo to /dir/foo.php
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*?)/?$ $1.php [L]
You can try:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
# handle ?param1=...
RewriteCond %{THE_REQUEST} \s/+(?:index\.php)?\?param1=([^\s&]+) [NC]
RewriteRule ^ /budget/%1.html? [R=301,L,NE]
# handle ?param2=...
RewriteCond %{THE_REQUEST} \s/+(?:index\.php)?\?param2=([^\s&]+) [NC]
RewriteRule ^ /user/%1.html? [R=301,L,NE]
## hide .php extension snippet
# To externally redirect /dir/foo.php to /dir/foo
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R=301,NE,L]
RewriteRule ^budget/([^/.]+)/?$ index.php?param1=$1 [L,QSA,NC]
RewriteRule ^user/([^/.]+)/?$ index.php?param2=$1 [L,QSA,NC]
# To internally forward /dir/foo to /dir/foo.php
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*?)/?$ $1.php [L]
Hello every one i am new in this concept of URL rewriting. i have url as like that "http://localhost/htaccess/formname/my-parameter-value"
but i want to as like that
"http://localhost/htaccess/my-parameter-value"
thanks in advance
here is my code
#Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+(.*?)(?:\+|%20|\s)+(.+?)\sHTTP [NC]
RewriteRule ^ /%1-%2 [L,NE,R=302]
# To externally redirect /dir/foo.php?name=123 to /dir/foo
RewriteCond %{THE_REQUEST} ^GET\s([^.]+)\.php\?name=([^&\s]+) [NC]
RewriteRule ^ %1/%2? [R,L]
# To internally forward /dir/foo/12 to /dir/foo.php?name=12
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+?)/([^/]+)?$ $1.php?name=$2 [L,QSA]
What I want:
/foo.php display /foo in url bar
/foo redirect to /foo.php
Both must view /foo.php
Must work with /showthread.php?id=00 (/showthread?id=00) and such
I constantly get a redirect loop even if I use [L] everywhere.
I tried these:
(1)
RewriteRule ^/forums$ forums.php [R]
RewriteRule ^/forums\.php$ forums [PT]
(2)
RewriteRule ^forums\.php/?$ forums [L,R=301]
RewriteRule ^forums/?$ forums.php
(3)
RewriteRule ^forums/?$ forums.php [L,R=301]
(4)
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/?([a-z/]+).php$ $1 [R,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (.*) $1.php [L]
Each of the above work for individually foo.php to foo or foo to foo.php but infinite loop on both.
I also tried this:
## don't touch /forum URIs
# RewriteRule ^forums/ - [L,NC]
## hide .php extension snippet
# To externally redirect /dir/foo.php to /dir/foo
# RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
# RewriteRule ^ %1 [QSA,R,L]
# To internally forward /dir/foo to /dir/foo.php
# RewriteCond %{REQUEST_FILENAME} !-d
# RewriteCond %{REQUEST_FILENAME}.php -f
# RewriteRule ^(.*?)/?$ $1.php [QSA,L]
Which works as expected but breaks a lot of site features for some reason. (search bar does not work, forums don't work, login doesn't work)
I need foo.php to still work because MyBB uses it.
Try this code in root .htaccess:
RewriteEngine On
RewriteRule ^forums/ - [L,NC]
## hide .php extension snippet
# To externally redirect /dir/foo.php to /dir/foo
RewriteCond %{REQUEST_METHOD} !POST
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R,L]
# To internally forward /dir/foo to /dir/foo.php
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+?)/?$ $1.php [L]
i have a problem on my htaccess file , i'm trying to hide all .php extensions on my website,
i tried many htaccess codes but most of it gives me errors , 404 Not Found , most of my files contain variables like ?id and ?category , index/?cat=Action , i want htaccess to hide php extension and forward /dir/foo to /dir/foo.php , help me pls :)
RewriteEngine On
RewriteBase /
# turn off index.php for home page
RewriteRule ^index\.php/?$ / [L,R=301,NC]
# To externally redirect /dir/foo.php to /dir/foo
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R,L]
You need to write php to the end of urls not the other way around. You can write variables like this: href="foo?bar=1". This code has worked for me:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
You can use this code in your root .htaccess:
RewriteEngine On
RewriteBase /
# To externally redirect /dir/file.php to /dir/file
RewriteCond %{THE_REQUEST} \s/+(?:index)?(.*?)\.php[\s?] [NC]
RewriteRule ^ /%1 [R=301,L,NE]
# To internally forward /dir/file to /dir/file.php
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1\.php -f [NC]
RewriteRule ^(.+?)/?$ /$1.php [L]
I have a code in my htaccess that removes the .php from every page on my site. The following code is as far as i came, but what i actually want is that every page has an slash after the name (still without php)
and that de index(.php) name is completely removed.
Icouldn't find something on the internet having these two combined. I did find a code that created a slash at the end but that created many problems with internally redirecting.
Is all of this possible and if so, how?
Many thanks in advance,
Paul
Options +FollowSymLinks -MultiViews
RewriteEngine On
# To externally redirect /dir/foo.php to /dir/foo
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R,L]
# To internally forward /dir/foo to /dir/foo.php
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*?)/?$ $1.php [L]
Try:
Options +FollowSymLinks -MultiViews
RewriteEngine On
# To externally redirect /dir/foo.php to /dir/foo
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ /%1/ [R,L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s(.*)index\.php [NC]
RewriteRule ^ /%1 [R,L]
# To internally forward /dir/foo to /dir/foo.php
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} ^(.+?)/?$
RewriteCond %{DOCUMENT_ROOT}%1.php -f
RewriteRule ^(.*?)/?$ /$1.php [L]