My question is, How can remove last directory using htaccess rule.
http://mywedding.com/anandn/
should load content of
http://mywedding.com/anandn/theme/
OR
http://mywedding.com/mamtaandkuldip/
should load content of
http://mywedding.com/mamtaandkuldip/theme/
Thanks in advance.
Place this rule in DocumentRoot/.htaccess file:
RewriteEngine On
RewriteRule ^([^/.]+)/?$ /$1/theme/ [L]
Inside
mywedding.com/anandn/index.php
write the following code
header("location:mywedding.com/anandn/theme/");
it will redirect you to your site.
Related
I want to rewrite url to css-files(looks like http://localhost/wordpress/my-page/assets/css/style.min.css) to new path (http://localhost/wordpress/my-page/my-project/app/assets/css/style.min.css). How can i do this?
Please use following code in .htacess file.
RewriteRule ^/wordpress/my-page/assets/css/style.min\\.css$ http://localhost/wordpress/my-page/my-project/app/assets/css/style.min.css [L]
I am trying to load a page (/user/profile.php) whenever the URL is sitename.com/u/[user_nicename]
How to achieve this by mod rewrite ?
I have tried the following but it is not redirecting properly,(shows 404 err)
here is my htaccess content,
RewriteEngine On
RewriteRule ^u/([^/.]+)/?$ /user/profile.php [L]
(I have created this .htaccess file in 'u' directory so that when a request like example.com/u/[something] is made, it will look for [something] file, when that is not found it tries to find 'u' directory where I have written this redirect)
Kindly help, all I am trying is to load a particular file ie., /user/profile.php whenever a request is like sitename.com/u/[user_nicename]
Thanks!
try this:
RewriteRule ^/u/(.*) /user/profile.php [L]
Since, you have this .htaccess inside the sub-directory u is implicit and not required in the rule.
RewriteEngine On
RewriteRule ^([^/]+)/?$ /user/profile.php [L]
I am new to htaccess and want to do following thing,
I want to rewrite url like,
http://example.com/test/test.php to http://example.com/test.html
and my htaccess file present in test folder. Can anyone help to find out this problem.
Thank You
That should do it:
RewriteEngine on
RewriteRule ^(.*).html$ test/$1.php [QSA]
How to redirect in url by using htaccess in php?
http://www.example.com/randomstring/2
i would like to go to id page 20 thank
You should use mod_rewrite for example in this way:
RewriteEngine On
RewriteRule ^(randomstring)/([0-9]+)$ /randomstring/$1/ [QSA,R]
RewriteRule ^(randomstring)/([0-9]+)/$ index.php?page=$1&id=$2 [QSA,NC,L]
If you want to simply redirect from a domain to another just write:
RewriteRule ^(randomstring)/([0-9]+)$ http://www.example.com/$1/$2/ [QSA,NC,L,R=301]
use mod_rewrite, it's a module for apache. You can see the documentation here. .htaccess files control the webserver, not php, so you have to look there.
Copy that into your .htaccess file in the directory you need it:
RewriteEngine On
RewriteRule ([A-Za-z0-9]+)/([0-9]+)$ index.php?id=$2
www.domain.tld/asdf/2 --> index.php?id=2
www.domain.tld/asdfa923als/52 --> index.php?id=52
;-)
I'm trying to convert a simple url (below) in to a blog-style url, but not quite sure how to do it, all of my other rules are working fine, but I can't seem to figure this one out.
URL I want to convert: http://www.website.com/myblog.php?id=1&title=My+blog+title
URL I want it to create: http://www.website.com/1/my-blog-title
What should the rule be?
Any assistance appreciated :)
Try this
RewriteEngine on
RewriteBase /
RewriteRule ([0-9]+)/([^.]+) myblog.php?id=$1&title=$2
Try this in your .htaccess file:
RewriteEngine on
RewriteRule ^(\d+)/([^/]+)$ myblog.php?id=$1&title=$2
But here the hyphens are not replaced by plus signs.
in your .htaccess file,
RewriteEngine On
RewriteRule ^([^/]*)/([^/]*)$ /myblog.php?id=$1 [L]
You don't (well shouldn't) need to pass the blog title to the blog file, only the ID. Hope this works