htaccess issue, change '/' to '.' - .htaccess

This is my first Question to StackOverflow. I have been working with .htaccess for a PHP application that is currently in development. My Contention is changing a forward slash to a period.
I have had no Joy so far, currently my code looks like the following:
RewriteRule ^([A-Za-z_-]+)?$ app/account/?account_name=$1 [NC,L]
The above is taking away the 'app/account/?account_name=account_name' and allowing displaying the following : www.exampleurl.com/examplename. This is fine, but is there anyway to change my code so instead of /examplename it states www.exampleurl.com.examplename ? I have spent some time googling the answer to no avail.
If anyone can give me some guidance that would be fantastic, thanks in advance.

I can't think of a real replace, but what you can if the nesting is limited to some number (let's say 3) is provide multiple rules each dealing with specific nesting level:
RewriteRule ^([^/]+)/([^/]+)/(.*) /$1.$2.$3 [L,QSA]
RewriteRule ^([^/]+)/(.*) /$1.$2 [L,QSA]
# third rule is not needed, because when there is only one level, there is nothing to replace
What you need to make sure is that the rules are in descending order of the nesting levels (L flag ensures processing is stopped on a level that is matched)

Related

Having issue with query string htaccess redirect

Tried looking via search but I couldn't find a match for this particular issue.
Needing to redirect /games/ps3/?page=2 to /ps3/games/2/. All of the approaches I've tried so far won't remove the query string and grab the page value to pass into my new URL.
A little bit new to these types of redirects as I don't work with them often, so I'm guessing it might be a RedirectRule-type approach but I'm not sure.
(Note that due to how the URLs work with other pages on the site I'm having to create the rule for each platform, i.e. I need have a separate rule for both ps3 and xbox-360. So the only variable here is the page number.)
I was thinking it might work something like
RewriteRule ^games/ps3/?page=(.*)$ /ps3/games/$1/? [L,R=301]
But I think the first ? is causing the rule to fail since the second part uses it. I tried looking online to see how to resolve that possible issue but I couldn't find anything.
Ended up messing around with the rules and got this to solve the issue:
RewriteCond %{QUERY_STRING} ^page=(.+)$ [NC]
RewriteRule ^games/ps3/$ /ps3/games/%1/? [L,R=301]

redirect old wordpress ?page_id= to non-wordpress site

I used to have a WP site that I converted to a standard html site. Problem is I found doing a google search that instead of http://www.genealogyinc.com it was returning http://www.genealogyinc.com/?page_id=21, I dont know how many pages are like this but am trying to find a htaccess workaround, all the ones I found online give me 500 server errors.
Need a rewrite for any ?page_id= cause I dont know how many other numbers are out there.
Thanks
Off the top of my head, without testing, it would be something like this.
The first line looks for the page_id querystring parameter, and if it meets it, it should pass on to the second line. The rewrite rule I have below may need some tweaking, but I hope this helps you.
RewriteCond %{QUERY_STRING} page_id=(.*)$
RewriteRule $ /? [R=301,L]

Redirect files and folders matching a prefix pattern

I am trying to redirect all requests to subfolders and subfiles in a directory that start with 4 numbers (e.g. 2012) to another directory using the .htaccess file.
For example,
/results/2005-09-19-xxx/* to /event/2005-09-19-xxx/*
and
/results/2005-09-20-file.ext to /event/2005-09-20-file.ext
But not
/results/anything-else/*
From the documents I have looked at I believe I need to use a RewriteCond followed by a RewriteRule. I have been struggling to find a way to both match on the initial 4 numbers and still use them in the redirected link.
I have spent many hours trying to find a solution to this issue, any help or advice would be much appreciated. Thank you.
You don't realy need a rewrite condition, try this rewrite rule :
RewriteRule ^results/([0-9]{4}.*)$ /event/$1 [L,QSA]
This should do the trick:
RewriteRule ^result/([0-9]{4})-([0-9]{2})-([0-9]{2})(.+)$ event/$1-$2-$3$4 [L]
This pattern is: 4 numbers dash 2 numbers dash 2 numbers rest, written in a way that you can easily understand and manipulate at a later date if need be. Everything that fits the pattern will be rewritten - the rest will work as it normally does
Example:
result/2012-02-02-abcd.ext
fits the pattern and will be rewritten to
event/2012-02-02-abcd.ext

.htaccess is there a more efficient way of doing this?

I have URLs in this format
site.com/brochure/12/subcat/subcat/maincat
The only important part of the string to my application is the number directly after brochure
There can sometimes be many subcat false directories so I've had to use many rules like these to make it work
RewriteRule ^brochure/([^/]+)/([^/]+)/([^/]+)/?$ brochure.php?cat_path=$1
RewriteRule ^brochure/([^/]+)/([^/]+)/([^/]+)/([^/]+)/?$ brochure.php?cat_path=$1
RewriteRule ^brochure/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/?$ brochure.php?cat_path=$1
etc etc - sometimes up to five different rules to allow for the different directory structures.
I'm guessing this can be done in a single rule, anyone kind enough to share their ideas?
Thanks
Since you don't care about any part of the string after your initial ([^/]+), why not just use something like:
RewriteRule ^brochure/([^/]+).*$ brochure.php?cat_path=$1
This will match and group your 12, then quietly match and discard the remainder of the string (.*$).

.htaccess redirect/rewrite help needed

I am writing htacess redirect rule but it is not working properly I have tried many solutions but simply it is not working.
What I want to do is to
I have url http://example.com/cms/index.php?page=filename I want this url to be executed and show appropriate page but in browser it should show example.com/cms. And what is important is I only want to right this rule for this page only and it should not effect to other pages.
Thank you.
RewriteRule ^([^/]+)/$ /cms/index.php?filename=$1 [L,QSA]
The L at the end says it is the last rule (stop processing) and QSA means 'Query String Append', so if someone puts other parameters after it, such as:
http://example.com/cms.htm?order=desc
The GET value for order will be passed also - without it it'll just quietly drop it.
Something like this ought to work:
RewriteEngine on
RewriteRule ^http://example.com/cms$ http://example.com/cms/index.php?page=filename
...should work.
Have a look at a tutorial with some examples if you're interested in seeing what else you can do.

Resources