I am new to the URL rewrite rules and would like to rewrite some URLs. Below is my problem:
I have created two rules (which works fine) that will hide the *.php extension from the URL. One is to redirect "/abc.php" to "/abc". Another rule is to Rewrite /abc as /abc.php. These two rules work fine and I use the following pattern.
^([^/]+)/?\.php$ --> Redirects to --> {R:1}
^([^/]+)/?$ --> Rewrites to --> {R:1}.php
Now I have a problem. I have a page which goes like www.example.com/member?getuser=chris (note that it's not member.php?getuser=chrisyeung because of the previous rules). I want to rewrite the URL to:
www.example.com/member/chris
I tried to follow some tutorials and use the following pattern:
`^/member/(_[0-0a-z-]+)` --> Rewrites to --> `^member?getuser={R:1}`.
...but it doesn't work.
What am I missing?
I don't unterstand your first two rules. Rewrite *.php to * and * to *.php - sounds like a loop for me. I assume your files are named .php and you want your visitors use URLs w/o this file extension. Then just rewrite * to *.php.
For your members pages, use:
^/member/([0-9a-zA-Z-_]+) member.php?getuser={R:1} [QSA]
I changes the list of valid characters inside the [] and I call member.php directly - no need for issuing another rule. QSA is for passing through further URL params.
Related
Basically I have a multiple language website. The URL of a selected language looks like this: website.com/?lang=EN
I have 30 languages. Is it possible to rewrite these URL's with applying a rewrite rule to cover them all to eg; website.com/en (website.com/"language")
check if the parameter exists and then use it for redirection, make sure to remove the parameter in your target url to avoid a redirect loop.
i.e. like this
if ($arg_lang!="") {
rewrite ^/$ https://website.com/$arg_lang?;
}
I'm trying to create a custom URL rewrite in wordpress. Basically, I want users to be able set their browser to mysite.com/.well-known/stellar.toml and get the contents of the following file I uploaded as a media file: mysite.com/content/uploads/2016/11/stellar.toml.
I tried the following rewrite rule in functions.php, then saved the permalinks to flush the rewrite rules, but it still didn't work. Anyone see what I may have done incorrectly?
function custom_rewrite_basic() {
// add rewrite rule
add_rewrite_rule('.well-known/stellar.toml','wp-content/uploads/2016/11/stellar.toml','top');
}
add_action('init', 'custom_rewrite_basic');
I have the following URLs:
/products/?term_id=3
/products/?term_id=3&post_id=66
What I would like to get is the following:
/products/termid-termtitle
/products/termid-termtitle/postid-posttitle
Rewritten as the original URLs.
I've tried a few ones I have found elsewhere but to no avail.
I have a wordpress site which has hundreds of articles with URLs in the following format:
http://www.example.com/news/variable-article-name-XXXXXXXXX/
where XXXXXXXXX is always a 9 digit number
I'd like to rewrite the URLs to include a slash before the number; to appear as follows.
http://www.example.com/news/variable-article-name/XXXXXXXXX/
Is there a simple, single rule I can write to achieve this?
Any help appreciated.
Try the following:
RewriteRule ^news/(.*)-(\d{9})/?$ /news/$1/$2 [R=301,L]
You'd still need some internal rewrite so that the redirected URL can be forwarded to appropriate pages.
i search a lot in the web and read many tuts and references but could not solve my problem! here is my problem: in my wordpress site i have some urls like this:
localhost/mysite/articles/?arc=8892
i have this url because in my php code i validate that article:
<?php
$article = wp_getpost($_GET['arc']); //arc = 8892
if($article->post_type == 'article')
//process article....
which 8892 is id of a post with article custom post type! also i have a plugin names custom post type permalink which set this style for this post type.
what i wanna do is rewrite below url to current urls:
localhost/mysite/article/8892
without any change in my php code.
in my htaccess code i have this but does not work:
RewriteRule ^articles/?([0-9]+)/?$ /articles/?arc=$1 [NC]
You don't have to write .htaccess manually, wordpress does it for you.
Just go to http://path/to/your/blog/wp-admin/options-permalink.php in yout browser and use one of the predefined url strucutres or write a custom one yourself.